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 access module properties / methods

In Phalcon Multi Module structure i thought it is possible to query between 2 different modules.

Like accessing :

properties / methods from Module A controller / model in Module B controller / model by using DISPATCHER.

But its not working.

If there is a global module which need to be accessed by other modules for some data, how do we do it?

Also looks like $Response->redirect() will also not work.



58.4k

Hi

You can upload your code??



3.6k

From Module A / Controller, If i dispatch within the same Module. Its working Perfectly.

$this->dispatcher->forward(array( 'controller' => 'Index', 'action' => 'test' ));

If i try to send dispatch to the different modules controller, Its not working.

$this->dispatcher->forward(array( 'module' => 'module_B', 'controller' => 'Index', 'action' => 'showdata' ));



58.4k

Hi

I saw information "Forwards the execution flow to another controller/action Dispatchers are unique per module. Forwarding between modules is not allowed" https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Dispatcher.html



3.6k

OK, So Dispatcher is working winthin a Module. Fine.

But atleast is there a way to access properties or methods of Controller MODULE B from Controller MODULE A?



58.4k
Accepted
answer
edited Apr '14

When you use multi-module in index.php files include multi-module or A special bootstrap file is required to load the a multi-module MVC architecture, //Create an application $application = new Application($di);

    // Register the installed modules
    $application->registerModules(
        array(
            'frontend' => array(
                'className' => 'Multiple\Frontend\Module',
                'path'      => '../apps/frontend/Module.php',
            ),
            'backend'  => array(
                'className' => 'Multiple\Backend\Module',
                'path'      => '../apps/backend/Module.php',
            )
        )
    );

    //Handle the request
    echo $application->handle()->getContent();

this is mean use dispatcher below alway working any module above

$this->dispatcher->forward(array( 'controller' => 'Index', 'action' => 'test' ));