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

render controler/action from other module

render controler/action from other module

app/frontend/view/index/index.php

<? render controler/action from other module ?>

implemented in ZF1 with Action View Helfer <?php echo $this->action('action', 'controller', 'module'); ?>

thank Pet



5.7k
edited May '15

I remember I asked this question last year and it may have change since then but the answer I received is that it is not possible. A module can not communicate with controllers/actions of other modules. I wanted to do the same so that I could render the login page if someone wasn't logged in from any module. But then I realized that by creating a form that can be called anywhere, it solved that problem. In my case, I had to rethink how I approached the issue.



2.9k

not good :(

you can components (controllers and views) Create a Plugin?

There is a way, but is a bit of a hack :)

    // set the views path to your desired module
    $this->view->setViewsDir('path/to/your/module/views/');
    // render view; must be written the way is on views folder
    $this->view->render('controller','action');
    // to render only the view, otherway it will render your current module and the new module page
    $this->view->setRenderLevel('LEVEL_ACTION_VIEW');


5.7k

I guess I should have asked if in the OP it was necessary to also execute/run the Controller with the action or if the task is to just render the view

If it's just to render a view, yes, it is possible and I would even go as far as to say if you have a view shared among modules, create a shared views directory.

There is a way, but is a bit of a hack :)

  // set the views path to your desired module
   $this->view->setViewsDir('path/to/your/module/views/');
  // render view; must be written the way is on views folder
   $this->view->render('controller','action');
  // to render only the view, otherway it will render your current module and the new module page
   $this->view->setRenderLevel('LEVEL_ACTION_VIEW');
edited May '15

I just did a test with latest phalcon 2.0.x and is working to forward to another module. Is executing the controller and the view

    // setting the views dir is a must, or it won't find the view, since is looking for the view in your current module view path
    $this->view->setViewsDir(APP_PATH.'modules/Tools/Views/');
    $this->dispatcher->forward(array(
        'module' => 'tools',
        'namespace' => 'Tools\Controllers',
        'controller' => 'index',
        'action' => 'index
        ')
    );


5.7k

Then it looks like things have changed since I asked last year :-)

I just did a test with latest phalcon 2.0.x and is working to forward to another module. Is executing the controller and the view

  // setting the views dir is a must, or it won't find the view, since is looking for the view in your current module view path
  $this->view->setViewsDir(APP_PATH.'modules/Tools/Views/');
   $this->dispatcher->forward(array(
       'module' => 'tools',
       'namespace' => 'Tools\Controllers',
       'controller' => 'index',
       'action' => 'index
      ')
  );