1
votes

I want to add a view helper path in an existing project. To do this I have added the following line to my application.ini:

resources.view[] =

And in my bootstrap file:

$this->bootstrap("view");
$view = $this->getResource("view");
$view->addHelperPath(APPLICATION_PATH . "/../library/MyPath", MyNamespace");

Now I am indeed able to add view helpers to my path, so no problem there.

However, variables that I have added to the view in my Action Helpers are suddenly no longer accessible inside my views. I can retreive them inside my layout as usual so I know they get assigned properly.

I assign a variable in my Action Helper in the postDispatch:

$view = $this->getActionController()->view;
$view->myVar = $this->var;

Then in my layout

Zend_Debug::dump( $this->myVar );

results in: (string) "myVar contents"

And in my view

Zend_Debug::dump( $this->myVar );

results in: null

Since this is an existing project I need a general solution that I can use in either my bootstrap or application.ini

2
maybe it's as simple as return $view; in your bootstrap. Probably not but it's worth a try. - RockyFord

2 Answers

0
votes

You can add paths to your view from application.ini:

resources.view.helperPath.MyPrefix = "/path/to/helpers"

Hopefully this will fix the problem. I'm assuming that the way you do it, an existing view-instance is somehow overwritten, which destroy previous changes. You could try fetching the view from the frontcontroller, set the helper-path, and pass it back to the frontcontroller.

0
votes

After some research this is what I found out.

Edit: Removed text concerning differences between view variables and layout variables - see comments by @pieter and @david weinraub

The postDispatch of the Action Helper fires AFTER the view is rendered, but BEFORE the layout is rendered. Therefore, any variables assigned to the view in the postDispatch of the action helper were unavailable in my views, they didn't exist yet.

I am very curious why this behaviour occurs ONLY when actively bootstrapping the view? I will leave the question unanswered, maybe someone can clarify this.