开发者

Using only layout from a controller

how do I make available some data for a layout/layout.phtml script without having to create a view script from a controller?

I've tried the following in indexAction function, but it does not work. When I do not create the view script I get an error. I could created empty one, but I don't like this solution much. Any better ideas?

$this->开发者_Python百科;layout->content = "foo"
$this->_helper->viewRenderer->setNoRender(true);

Thanks in advance


You don't actually render some data you make the data available and then choose which script to render. Don't confuse the terminology.

What you have done there is stopped any script from being rendered by using the :

$this->_helper->viewRenderer->setNoRender(true);

When you do

$this->layout->content = "foo";

You are setting the property content, which you then neeed to make use in your layout script.

So then in your layout.phtml script (which I hope you have already configured to render by efault) you then just do this

 echo $this->content

Notice that I don't actually use $this->layout because when you are inside the layout, $this equal $this->layout. The same goes for $this->view->foo is $this->foo inside your view.

I hope this helps. Any questions just ask.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜