77use Phalcon \DI \FactoryDefault ;
88use Phalcon \Db \Adapter \Pdo \Mysql ;
99use Phalcon \Url as UrlProvider ;
10+ use Phalcon \Mvc \View \Engine \Volt ;
11+ use Phalcon \Loader ;
1012
1113$ di = new FactoryDefault ();
1214$ di ->setShared (
@@ -43,11 +45,48 @@ function () {
4345/**
4446 * Setting the View
4547 */
46- $ di ->setShared ('view ' , function () {
48+ $ di ->setShared ('view ' , function () use ( $ di ) {
4749 $ view = new View ();
50+ // $view->setViewsDir(BASE_PATH . '/_data/App/Views/');
51+ // $view->registerEngines(
52+ // [
53+ // ".volt" => "voltService"
54+ // ]
55+ // );
56+ // $eventsManager = $di->get('eventsManager');
57+ // $eventsManager->attach('view', function ($event, $view) use ($di) {
58+ // /**
59+ // * @var \Phalcon\Events\Event $event
60+ // * @var \Phalcon\Mvc\View $view
61+ // */
62+ // if ($event->getType() == 'notFoundView') {
63+ // $message = sprintf('View not found - %s', $view->getActiveRenderPath());
64+ // throw new Exception($message);
65+ // }
66+ // });
67+ // $view->setEventsManager($eventsManager);
4868 return $ view ;
4969});
5070
71+ /**
72+ * Volt Service
73+ */
74+ $ di ->set (
75+ 'voltService ' ,
76+ function ($ view ) use ($ di ) {
77+ $ volt = new Volt ($ view , $ di );
78+
79+ $ volt ->setOptions (
80+ [
81+ 'compiledPath ' => BASE_PATH . '/_output/compiled-templates/ ' ,
82+ 'compiledExtension ' => '.compiled ' ,
83+ ]
84+ );
85+
86+ return $ volt ;
87+ }
88+ );
89+
5190/**
5291 * The URL component is used to generate all kind of urls in the application
5392 */
@@ -60,10 +99,9 @@ function () {
6099
61100$ router = $ di ->getRouter ();
62101
63- $ router ->add ('/contact ' , [
64- 'controller ' => 'App\Controllers\Contact ' ,
102+ $ router ->add ('/ ' , [
103+ 'controller ' => 'App\Controllers\Index ' ,
65104 'action ' => 'index '
66- ])->setName ('front.contact ' );
67-
105+ ])->setName ('front.index ' );
68106
69107return new Application ($ di );
0 commit comments