Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



36.4k

Hi

You can upload your code??



2.1k

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' ));



36.4k

Hi

I saw information "Forwards the execution flow to another controller/action Dispatchers are unique per module. Forwarding between modules is not allowed" http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Dispatcher.html



2.1k

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?



36.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' ));