I have some controller Index. There I defined variable:开发者_运维知识库
class IndexController extends Zend_Controller_Action
{
function IndexController()
{
$this->view->some_val = 100;
}
}
And the layout is like this:
<html>
<p><?= $this->some_val; ?></p>
<?= $this->getLayout()->content; ?>
</html>
But in th this case I get NULL instead of 100. I tried to define it in preDispatch function but result is the same. Could anybody help pls? Thanks to all in advance
One one would be as @Yanick Rochon wrote. Another way would be to assing variables directly to your layout(), e.g.
class IndexController extends Zend_Controller_Action
{
function IndexController()
{
$this->view->layout()->some_val = 100;
}
}
Then in your layout;
<p><?= $this->layout()->some_val; ?></p>
If you need to save a reusable variable, use the placeholder
view helper
public function indexAction() {
$this->view->placeholder('some_value')->set(100);
}
and in any view script, or layout
echo $this->placeholder('some_value')->getValue(); // -> 100
精彩评论