I have a variable called $total in my action
public function totAction()
{
$开发者_JAVA百科total = 15;
}
I want to access it in an action helper. What should I do? Do I need to pass it to the view and read it from the view? Is there a more direct way to read this variable from an action helper?
If you make $total a public property of the controller, you can access it in the action helper
//in controller
$this->total = 15;
// in helper
$this->getActionController()->total;
You could also get an instance of the action helper in the controller, and set the property on the action helper, or just pass it into the helper via the direct:
$this->getHelper('Helper')->total = 15;
$this->_helper->Helper(15);
精彩评论