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

Phalcon 2.0 forward module

Can i dispatch action from module/namespace one to another action in module/namespace two in phalcon 2.0 ? I know i cant do it with phalcon 1.3 but is it possible with phalcon 2.0 ?



98.9k

The dispatcher is designed to work per module and not having one for all modules

edited May '15

So i guess the only way to do this is to register in my module A namespace where i store controllers from module B ? Then it should work ? How about register namespaces for models and controllers for whole application, so i can acces them from anywhere ? Is this gonna cost me a lot time? I know modules should be theortically independent, but i just like to build it like one funcionality = one module/directory.

edited May '15

Hello,

You can use something like that

        $dispatcher->forward(array(
                'module' => 'core',
                'namespace' => 'Core\Controllers',
                'controller' => 'error',
                'action' => 'show404'
            )
        );

But I'm not sure in how many cases work tho. I use it for page forwarding on error beforeException. And in controller you have to specify the view path.

Why don't you try a redirect to the controller in the different module as you work with session data.

If i want redirect then i would use redirect. Redirect = another request, forward = all in one request, thats why i dont want redirect.