Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how to solution the same controller in different sub dir

I created an sub folder admin in controllers folder, Now here have two file: controllers/loginController.php and controllers/admin/loginController.php, I want to call controllers/admin/loginController.php but the controllers/loginController.php always been can i do..

The easiest way is to use namespaces in PHP


Thanks for your answer, but the controller is called when the application is initialized, not manually calling. can it works?


Yes, Its work easily. Move all admin controllers to Admin namespace then add following code to your application bootstrap:

    // Loader, registering namespaces
    $loader = new Phalcon\Loader();
        'Admin'   => YOUR_APP_PATH . '/controllers/admin',

and add these lines to your router settings:

        $admin = new \Phalcon\Mvc\Router\Group(array(
            'namespace'     => 'admin',
            'controller' => 'index',
            'action'     => 'index'

        $router->add('/admin(/:controller(/:action(/:params)?)?)?', array(
            'namespace'     => 'admin',
            'controller' => 2,
            'action'     => 4,
            'params'     => 6,


        return $router;


thanks man! I like code examples....