How to use "Main Layout" views in a Phalcon multiprocessor application?

I am using an MVC framework with several modules for my PhalconPHP application.

One problem I'm trying to figure out is how I can customize the Main Layout view over the module view folders.

In other words, I need one Master Layout wizard ( as described here ), and I want all my modules to display their views on the Controller View in this main layout view.

By default, the Main Layout view from

[app] [module1] [controllers] [models] [views] (main layout is coming from here) [module2] [controllers] [models] [views] (main layout is coming from here) [views] (master main layout should come from here?) 

Hope this makes sense!

+4
source share
3 answers

What you are looking for cannot be performed in this version (0.5.0 stable) or the next version 0.6.0 (since it is frozen, a release is expected).

In your module you register your submissions

 // /module1/Module.php // Registering the view component $di->set( 'view', function () { $view = new \Phalcon\Mvc\View(); $view->setViewsDir('../apps/module1/views/'); return $view; } ); // /module2/Module.php // Registering the view component $di->set( 'view', function () { $view = new \Phalcon\Mvc\View(); $view->setViewsDir('../apps/module2/views/'); return $view; } ); 

etc.

You can also have a general view that will be distributed to all modules, but is not a combination of the two.

 //Registering a shared view component $di->set( 'view', function() { $view = new \Phalcon\Mvc\View(); $view->setViewsDir('../apps/views/'); return $view; } ); 

See this example on Github.

It could very well be NFR for version 0.7.

+2
source

In Phalcon ver 1.2.4 (possibly in earlier versions), a single master layout wizard is possible. Phalcon builds a lauout path relative to ViewsDir, which sets how

 $view->setViewsDir('../apps/views/'); 

So if you set the lauout path relative to this, it will work

 $view->setLayoutsDir('./../../views/'); 

Maybe the best way to organize this structure is to declare a view object when initializing the application, and when ViewsDir is installed in Module.php:

 // Application.php $di->set('view', function() use ($config) { $view = new View(); $view->setLayoutsDir('./../../views/'); $view->setLayout('index'); }, true); 

and

 // /module1/Module.php $di->get('view')->setViewsDir('../apps/module1/views/'); 
+1
source

You can use several shared demo layouts or download to see how it works https://github.com/phalcon/mvc/tree/master/multiple-shared-layouts/apps

Or just add tfor for each .php module

  $di['view'] = function () { $view = new View(); $view->setViewsDir(__DIR__ . '/views/'); $view->setLayoutsDir('../../common/layouts/'); $view->setTemplateAfter('main'); return $view; }; 
0
source

Source: https://habr.com/ru/post/1440489/


All Articles