开发者

reading action variable from action helper

开发者 https://www.devze.com 2023-02-22 13:42 出处:网络
I have a variable called $total in my action public function totAction() { $开发者_JAVA百科total = 15;

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消