Hi every body,

I’m bringing back a subject about global view variables which have already been discussed here http://www.nabble.com/Why-Zend_View_Helper_Partial-clears-all-assigned-variables-in-cloned-views--td15701331.html

With global view variables I mean view variable setup in the bootstrap and shared across views and partials. I mostly use them to store the url of the application assets (css, images, javascript, swf, ...). I find this method more elegant than using globals or constants.

I did this before partials and placeholder exits.

But now all the view variables are clear in the partials helpers so I need to overload the partials cloneView() method and with the help of the Zend_Registry I declare which vars are globals so they are not cleared. Not very elegant though…

In the above thread Matthew recommend to use the placeholders helper to be able to use view variables with global space.
But I’m to sure on how to properly use it :

Right now I’m doing something like this in my bootstrap:

$view->urlRoot = 'http://'.$_SERVER['HTTP_HOST'].$appConfig->url->base;
$view->urlAssets = 'http://'.$appConfig->url->assets;
$view->urlImages = $view->urlTheme.'/images';
$view->urlSwf = $view->urlTheme.'/swf';
$view->urlMedias = $view->urlAssets.'/medias';
$view->urlCss = $view->urlTheme.'/css';
$view->urlJs = $view->urlTheme.'/javascript';

So should I do:

1) One placeholder + key

$this->placeholder('Mmx_View_Globals')->urlRoot
$this->placeholder('Mmx_View_Globals')->urlAssets
$this->placeholder('Mmx_View_Globals')->urlTheme
$this->placeholder('Mmx_View_Globals')->urlImages

2) A placeholder for each var

$this->placeholder('urlRoot')
$this->placeholder('urlAssets')
$this->placeholder('urlTheme')
$this->placeholder('urlImages')

3) A special helper which extends Zend_View_Helper_Placeholder_Container_Standalone

$view->globals()->urlRoot
$view->globals()->urlAssets
$view->globals()->urlTheme;
$view->globals()->urlImages

4) Keep using my current setup

5) Other suggestions?

What are your recommendations ?
I'm curious to know how others tackled this problem too.



Thanks for ridding this topics,

Regards,

--
Laurent Melmoux
Conseil et Solutions Web | [EMAIL PROTECTED]
2mx - Annecy, France     | http://www.2mx.fr/


Reply via email to