views:

185

answers:

2

I set a view variable in someAction function like this:

$this->view->type = "some type";  

When I access this variable inside layout script like this:

<?php echo $this->type ?>

it prints nothing. What's wrong?

My application.ini settings related to layout

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.layout.layout = "layout" ; changed 'default' to 'layout'

Edit

This thread suggests the alternate solution, but looking for solution to above problem. And this was working in Zend 1.6.2. I just upgraded to 1.10 and it stopped working.

Edit

If I set this view var inside any _init Bootstrap function, it works.

+3  A: 

If you want to assign something to your layout you have to go an other way:

// get the layout instance
$layout = Zend_Layout::getMvcInstance();

// assign fooBar as Name to the layout
$layout->name = 'fooBar';
ArneRie
@ArneRie: This is the same solution as posted in alternate link I mentioned in edit.
understack
Just tested it with ZF 1.10.1 it works, please remember. You have to use <?php echo $this->layout()->name; ?>
ArneRie
@ArneRie:yes, your solution works but my question is why view vars couldn't be accessed directly? And it used to work earlier. Please also see my 2nd edit.
understack
A: 

Do you have the following entry in your application.ini file?

resources.view[] =

So, you can initialize the view with no options and use it through:

<?php echo $this->type ?>
bitfox
This doesn't work in layout script.
understack
Have you done the bootstrap of view through: $this->bootstrap('view'); placed in a resource method of bootstrap.php file?
bitfox