7
7
use Phalcon \DI \FactoryDefault ;
8
8
use Phalcon \Db \Adapter \Pdo \Mysql ;
9
9
use Phalcon \Url as UrlProvider ;
10
+ use Phalcon \Mvc \View \Engine \Volt ;
11
+ use Phalcon \Loader ;
10
12
11
13
$ di = new FactoryDefault ();
12
14
$ di ->setShared (
@@ -43,11 +45,48 @@ function () {
43
45
/**
44
46
* Setting the View
45
47
*/
46
- $ di ->setShared ('view ' , function () {
48
+ $ di ->setShared ('view ' , function () use ( $ di ) {
47
49
$ 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);
48
68
return $ view ;
49
69
});
50
70
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
+
51
90
/**
52
91
* The URL component is used to generate all kind of urls in the application
53
92
*/
@@ -60,10 +99,9 @@ function () {
60
99
61
100
$ router = $ di ->getRouter ();
62
101
63
- $ router ->add ('/contact ' , [
64
- 'controller ' => 'App\Controllers\Contact ' ,
102
+ $ router ->add ('/ ' , [
103
+ 'controller ' => 'App\Controllers\Index ' ,
65
104
'action ' => 'index '
66
- ])->setName ('front.contact ' );
67
-
105
+ ])->setName ('front.index ' );
68
106
69
107
return new Application ($ di );
0 commit comments