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

Get content from another action

Is there a way to do something like

$dispatcher->forward (array(
    "controller" => "posts", 
    "action" => "getByUser", 
    "params" => array ($userId, $page) 
)); 

But do not show value, just get a result in some variable and continue to work?

edited Sep '14

I'm not sure exactly what your problem is but I'm guessing from your wording that you are seeing the view belonging to the sending action not the receiving action?

Say your sending action is PostsController::firstAction(), then you'd expect to see views/posts/first.volt. After the forwarding to PostsController::getByUserAction($userId,$page) you'd expect to see views/posts/getbyuser.volt, but you still see views/posts/first.volt?

If I'm understanding you correctly you need to pick the new view: $this->view->pick("posts/getbyuser")

i.e.:

$this->view->pick(...);
$this->dispatcher->forward(...);

You can use

$this->view->disable();
return $data;

To disable the view and return the information you need. You will however need to make sure that the request is coming from with your App rather than a web request to make sure that the view is still displayed when used normally.

Yep, but how i can call this?

$pc = new PostsController();
$posts = $pc->getByUser($user->id)

?