I am trying to setup a router which recognizes controllers and actions automatically but uses different namespaces for frontend and backend.
For instance /some/stuff
should be recognized as \Mysite\Mvc\Controller\Frontend\SomeController::stuffAction
, when /backend/dashboard/analytics
should be recognized as \Mysite\Mvc\Controller\Backend\DashboardController::analyticsAction
.
Looks like it works properly right now, but there is one issue when I enter /backend/
url, it doesn't recognize as \Mysite\Mvc\Controller\Backend\IndexController::indexAction
, it is recognized as \Mysite\Mvc\Controller\Frontend\BackendController::indexAction
. What am I doing wrong?
Here is my router setup stuff:
$backend = new \Phalcon\Mvc\Router\Group( array( 'namespace' => 'Mysite\Mvc\Controller\Backend' ) );
$backend->setPrefix( '/backend' );
$backend->add( '/:controller/:action/:params', array( 'controller' => 1, 'action' => 2, 'params' => 3 ) );
$backend->add( '/:controller/:action', array( 'controller' => 1, 'action' => 2 ) );
$backend->add( '/:controller', array( 'controller' => 1, 'action' => 'index' ) );
$backend->add( '/', array( 'controller' => 'index', 'action' => 'index' ) );
$router = new \Phalcon\Mvc\Router();
$router->removeExtraSlashes( true );
$router->setDefaultNamespace( 'Mysite\Mvc\Controller\Frontend' );
$router->setUriSource( \Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI );
$router->notFound( array( 'controller' => 'index', 'action' => 'route404' ) );
$router->mount( $backend );
$router->add( '/:controller/:action/:params', array( 'controller' => 1, 'action' => 2, 'params' => 3 ) );
$router->add( '/:controller/:action', array( 'controller' => 1, 'action' => 2 ) );
$router->add( '/:controller', array( 'controller' => 1, 'action' => 'index' ) );
$router->add( '/', array( 'controller' => 'index', 'action' => 'index' ) );
return $router;
P.S.: I don't want to use modules.