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

Controller and layout name in views directory

Is it a bug or a feature? Or I've just missed something in documentation.

For example I have an IndexController::indexAction().

If I define routes in a class extended from \Phalcon\Mvc\Router\Group then view rendering from views/index/index.phtml. Routes are mounting using Phalcon\Mvc\Router\Annotations::mount() function.

But if I use \Phalcon\Mvc\Router\Annotations::addModuleResource() to add module-related routings then views are looking in different folder. Instead of views/index/index.phtml they should be placed in views/Index/index.phtml. Controller name is capitalized.

Layout acts the same way. It should be in views/layouts/index.phtml or in views/layouts/Index.phtml, respectively.

Unfortunately, I want to use both way to define routes, as annotation and mount them to router. Is it possible?


Some code expamles.

My controller class:

namespace Frontend\Controller;

 * @RouterPrefix("/")
class IndexController extends \Phalcon\Mvc\Controller
     * @Get("home", name="home")
    public function indexAction()

Routes in class

class Routes extends \Phalcon\Mvc\Router\Group
    public function initialize()
            'module' => 'frontend',
            'namespace' => 'Frontend\Controller',


        // Route to homepage
        $this->add('home', [
            'controller' => 'index',
            'action' => 'index',

Application bootstrap:

$router = new \Phalcon\Mvc\Router\Annotations(false);

$router->addModuleResource('frontend', 'Frontend\Index'); // *1*
$router->mount(new Routes()); // *2*

For line 1 beforeExecuteRoute $dispatcher->getControllerName() === 'Index'

For line 2 $dispatcher->getControllerName() === 'index'


Have fixed issue with the following code in dispatcher:

        $di->set('dispatcher', function () {
            //Create an EventsManager
            $eventsManager = new EventsManager();

            //Camelize controller
                function ($event, $dispatcher) {
                    $controller = Text::camelize($dispatcher->getControllerName());

            $dispatcher = new Dispatcher();

            return $dispatcher;

So, I simply capitalize every controller name.