Reputation: 3218
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
Upvotes: 0
Views: 208
Reputation: 238139
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>
Upvotes: 2
Reputation: 53526
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
Upvotes: 2