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 views

Hi, could somebody please tell me what am I doing wrong in this method ?

public function indexAction()
{
    $this->view->render('signin','register', ['msg' => 'error' ]);   
}

And in a view I try to output it

{% if msg is defined %}
    {{msg}}
{% endif %}

And I don't get anything in the output. In DI I use \Phalcon\Mvc\View() for the view. What can be causing a problem?



2.0k
edited Jul '14

You need to print the content:

echo $this->view->render('signin','register', ['msg' => 'error' ]);


28.4k

Doesn't work. And anyway, I wouldn't want to echo something out from a controller



2.0k
edited Jul '14

I think you have another view too, so you need to disable the rendering after the new one:

$this->view->render('ads','index')->disable();

and than you do not need to print them :)



28.4k

Didn't work neither.



28.4k

Maybe this is a bug in Phalcon 1.2.6?



98.9k
edited Jul '14

I don't think Phalcon\Mvc\View is supposed to work this way. You can see in the 'Views' chapter that we have a hierarchical rendering which automatically chooses the view that must be rendered according to the latest controller/action executed and a simple view rendering more likely the approach you want to adopt which requires produce the output right in the action.



28.4k

I know about it's default view loading, but I was wondering why this method won't work as expected?



98.9k

It doesn't work because it's not expected or supposed to work that way.



28.4k
edited Jul '14

Then what is the point of that method?



98.9k

The purpose of that method is render views but you don't have to call it specifically.



2.0k

In 1.3.1 my solution is working, i try it

$this->view->render('ads','index')->disable();

But i think the right way is that if u forward ur request to the signin->register method.