We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Multi Module Routing problem

Hi there,

I got a problem with the router in a multi module Application First things first, my code

Frontend/Module.php

index.php

routing.php

So my error is "PhalconException: Frontend\Controllers\DeController handler class cannot be loaded"

the directory structure is pretty simple

/app/backend/{MVC Structure} /app/frontend/{MVC Structure} /app/backend/Module.php /app/frontend/Module.php /app/Routing.php /public/index.php

The router tells me, that the route matched is that default one, where the pattern is /controler/action before setting up the multi module thing, the router was doing fine ... I just tried everything but there seem to be no way to get this thing to work.

Anyone any idea ?

If you need further information, please let me know.

Grettings

Hi,

You'll probably need to check the filenames and paths for case sensitivity.

I don't know if the links you provided show the accurate filename / paths: Frontend/module.php I think the module.php should be Module.php. The DeController.php should be named with a starting case.

I've used the code below in my bootstrap to see the path of the controller file Phalcon tries to load, try adding it before creating your Application object:

        $eventsManager = new \Phalcon\Events\Manager();
        $loader = new \Phalcon\Loader();
        //Debugging stuff for linux paths, case sensitive buggers
        //Listen all the loader events
        $eventsManager->attach('loader', function($event, $loader) {
            if ($event->getType() == 'beforeCheckPath') {
                echo $loader->getCheckedPath().'<br />';
            }
            if($event->getType() == 'afterCheckPath') {
                echo('path not found');
                die;
            }
        });

        $loader->setEventsManager($eventsManager);
        $loader->register();
edited Mar '15

This is my Phalcon multimodule routing implementation:

// in app/bootstrap.php
$router = new Phalcon\Mvc\Router(false);
$router->setDefaultModule('site');
$router->setDefaultController('index');
$router->setDefaultAction('index');

$router->add('/:module/:controller/:action/:params', array(
    'module'     => 1,
    'controller' => 2,
    'action'     => 3,
    'params'     => 4
));

foreach ($application->getModules() as $module) {
    $routesClassName = str_replace('Module', 'Routes', $module['className']);
        if (class_exists($routesClassName)) {
        $routesClass = new $routesClassName();
        $router      = $routesClass->add($router);
    }
}
$router->removeExtraSlashes(true);
$di->set('router', $router);

and finally repeat below code in each module route class (for example my Site module):

// app/modules/Site/Routes.php
namespace Site;

class Routes
{
    public function add ($router)
    {
        // Homepage router
        $router->add('/', array(
            'module'     => 'site',
            'controller' => 'index',
            'action'     => 'index',
        ))->setName('home');

        $router->add("/site", array(
            'module'     => 'site',
            'controller' => 'index',
            'action'     => 'index',
        ));

        $router->add('/site/:controller', array(
            'module'     => 'site',
            'controller' => 1,
            'action'     => 'index',
        ));

        $router->add('/site/:controller/:action', array(
            'module'     => 'site',
            'controller' => 1,
            'action'     => 2,
        ));
        $router->add(
            "/site/:controller/:action/:params",
            array(
                'module'     => 'site',
                "controller" => 1,
                "action"     => 2,
                "params"     => 3,
            )
        );


105

@iamtartan

I am trying to start a large project with multi-module(publisher/advertiser/admin/common/api_v1/api_v2 etc), multi-database(pubdb/advdb etc), could you please share your project folder structure with code? Thanks in advance.