1

I have a custom controller action helper that I would like to be able to call from a view script. How can I achieve this?

Solution:

Warning: You probably don't really want to call an action helper from your view script unless you aren't using any dispatch hooks. But if you really, really want to call your action helper:

$helper = Zend_Controller_Action_HelperBroker::getStaticHelper('Myhelper');

1 Answer 1

3

Afaik, you can't, and you should not that's MVC. Trying to solve such problem should be a potential warning on your design.

However, in some case you may need to achieve a similar thing.

For example, the flashMessenger() action helper aims to provide a simple way to share messages between requests, however it is not available in the view, you need to manually pass it to the view. I've myself written a wrapper to be able to use as a view helper.

So maybe try to be more explicit on what you're trying to achieve, and we may help you to know if there isn't a good alternative.

Sign up to request clarification or add additional context in comments.

3 Comments

Good answer. I just realized what I was trying to do wasn't going to work anyway. I was trying to call some action helper functions in my layout, but postDispatch() had already been called, so it wasn't going to do anything after my postDispatch() code had executed. Back to the drawing board...
Any chance of adding that FlashMessenger view-helper to your excellent bgylibrary on github? ;-)
Hi David, thank you :), I just pushed that view helper on github. The usage is not yet documented but it's pretty straighforward, it is just a wrapper to the flashmessenger action helper.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.