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

Dispatch to another module in a multi-module app

Hi, I' using phalcon 3.x with Multi module. Please help me use exception with Dispatch forward: This command not working

$dispatcher->forward(array(
    'module' => 'abc',
    'controller' => 'index',
    'action'     => 'show404'
));
return false;

It will work as soon as you will register controller from this other module i think.



85.5k
edited Aug '16

eturn $this->dispatcher->forward(array(
    'module' => 'abc',
-  'controller' => 'index',
    'action'     => 'show404'
));

//or

return $this->response->redirect('/abv/index/show404');

meh.. i was wrong accodring to docs you cant

Forwards the execution flow to another controller/action Dispatchers are unique per module. Forwarding between modules is not allowed

so you have to use the second option - the redirect



2.7k

Or you can duplicate error pages in each module.

edited Aug '16

Well i have forward in one of my apps. You just need to make sure that proper controller from other module is registered in current module. Oh sorry, actually it's not forwarding to module, just to namespace:

namespace Suzuki\Module\Error\Controller;
$this->dispatcher->forward([
                    'namespace' => 'Suzuki\Module\Frontend\Controller',
                    'controller' => 'index',
                    'action' => 'error',
                ]);

Just in your module:

        $loader = new Loader();
        $loader->registerNamespaces([
            'Suzuki\Module\Error\Controller' => $config->module->controllerDir, // notice here i register both controller namespace from two modules
            'Suzuki\Module\Frontend\Controller' => $config->module->frontendControllerDir,
            'Suzuki\Module\Frontend\Service' => $config->module->frontendServiceDir,
        ]);
        $loader->register();

Thank the enthusiastic help of friends. And only caught this problem. This is my website https://160825.fdola.com/ Using Nginx, Phalcon 3, speed is impressive, thanks phalcon group