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?



1.4k
edited Jul '14

You need to print the content:

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


17.6k

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



1.4k
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 :)



17.6k

Didn't work neither.



17.6k

Maybe this is a bug in Phalcon 1.2.6?



83.4k
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.



17.6k

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



83.4k

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



17.6k
edited Jul '14

Then what is the point of that method?



83.4k

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



1.4k

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.