Zend are view variable available inside view helpers?
I am wondering if Zend view 开发者_JAVA百科variables are available in my view helper class without passing them in directly as parameters
thanks
Luca
As all view helpers have reference to the view in their $view
property, the answer is yes.
What you won't know from the helper side is which properties are available. It would be better to pass any required properties to the helper at call or construction time.
well you can access $view
form inside the view helper , i will give an example :
in the example below you can set and get view vars
<?php
class App_View_Helper_Job extends Zend_View_Helper_Abstract {
public function setView(Zend_View_Interface $view) {
$this->view = $view;
}
public function job() {
$this->view->var1 = "testing var1 ";
$this->view->var2 = $this->view->var1;
}
}
You should know one thing:
view helper's view instance is the one set on helper instantiation It is not updated on view cloning. So you can't say for sure which one you're using if called from partial for example.
I found that when I set the view instance in registry and get it from helper the view variables stays. Here is a code snippet I used in my social engine project
$view = Zend_Registry::get('Zend_View');
/*
* Check data available and set it to local variable
*/
if(isset($view->localeTranslations[$key]))
{
$translate = $view->localeTranslations[$key];
}
精彩评论