开发者

Zend Form can't use action helper

My action helper just echos "ok" when called

class Helper_MyActionHelper extends Zend_Controller_Action_Helper_Abstract {
   public function direct(){
      echo "ok";
   }
}

When I test it in my controller, it works fine and echos ok.

$this->_helper->myActionHelper();

But when I do the same thing in a form, it doesn't w开发者_JAVA技巧ork at all. I tried

$this->_helper->myActionHelper();
$this->_helper->myActionHelper;

So can I use an action helper in a form.. is there a way around it?


You can use :

$helper = Zend_Controller_Action_HelperBroker::getStaticHelper('MyActionHelper');
echo $helper->direct();

Look at The Helper Broker section in the documentation : http://framework.zend.com/manual/en/zend.controller.actionhelpers.html


A more accurate name for Action Helpers would be Action-Controller helpers. They're meant to be called from action controller methods. You cannot, out of the box, call them from other Zend objects.


Action Helpers are not designed to 'help' non-action elements of your application.

Your $form has no concept of registered action helpers ($this->_helper) or even the context in which the helpers are configured.

You can read up here and learn where plugins work within the Zend Framework lifecycle: http://www.eschrade.com/page/zend-framework-request-lifecycle-4b9a4288

If you revise your question and let us know what you're trying to accomplish, we might be able to suggest alternative methods.


You could always pass the myActionHelper object to the form as a paramater.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜