We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Using route specific view folder

Well let me first describe my scenario.. I am using folder to group my controllers file in section... like admin panel related controllers, I placed them in ../controllers/admin/{controllerfiles}.php ... For that I have created route specific to it. But the problem is that I can't group view files for that under something like this ../views/admin/{controller}/{action}.phtml . I have read through docs, without a luck, to follow the scheme I am using.

edited Sep '18

Use modules and register new view service in each module with other view path. Also it should be like admin/controllers actually and admin/views etc.

I have an untested and perhaps unwise solution: Have each admin-panel-related controller extend a base admin-panel-related controller. In that base controller's beforeExecuteRoute() method, create a local version of view and set the views directory:

namespace Controller\Admin;

class Base extends \Phalcon\Mvc\Controller{

    public function beforeExecuteRoute(){
        $this->view = $this->di->get('view');
namespace Controller\Admin;

class UsersController extends Base{