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.



67.7k
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



1.4k

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 http://160825.fdola.com/ Using Nginx, Phalcon 3, speed is impressive, thanks phalcon group