Using routes in multi-module app - best practices?

Hey guys,

I'm wondering how do you handle routing in multi-module application?

I've been checking if URI starts with 'backend' and then include backend routes only, or frontend routes otherwise. Although it feels really dirty, I've been using this aproach for two reasons:

  1. I wanted to separate 404 pages for frontend & backend
  2. I was afraid I'm going to cripple performance with too many routes (both frontend and backend).

Regarding number 2, how many routes would be "too much" ?



46.7k

Router Config:

$router->setDefaultModule('frontend');
$router->addStdModule('backend');

// Explicit Routes Method 1
$router->add('/signin', 'frontend::session::signin');
// Explicit Routes Method 2
$router->add('/signin', [
    'module'      => 'frontend',
    'controller'  => 'session',
    'action'      => 'signin'
]);

Extended Router class:

class Router extends PhRouter
{

    public function setDefaultModule($moduleName)
    {
        parent::setDefaultModule($moduleName);
        $this->addStdModule($moduleName);
    }

    public function addStdModule($moduleName)
    {
        $this->add("/$moduleName", [
            'module' => $moduleName,
            'controller' => 'index'
        ]);
        $this->add("/$moduleName/:controller", [
            'module' => $moduleName,
            'controller' => 1
        ]);
        $this->add("/$moduleName/:controller/:action", [
            'module' => $moduleName,
            'controller' => 1,
            'action' => 2,
        ]);
        $this->add("/$moduleName/:controller/:action/:params", [
            'module' => $moduleName,
            'controller' => 1,
            'action' => 2,
            'params' => 3
        ]);
    }

}