Zend: Action Helper Vs View Helper

Hi,

I’m learning Zend (clearly!)

And I was wondering what the difference is between an action helper and a view helper. When I go over the material I have (“Easy PHP Websites with the Zend Framework” book) I can’t really tell the difference between the two. Functionally they appear to fill the same role… Why would I choose one over the other? What is the purpose of each one?

Thanks!!

View Helpers can be called from views, and action helper from controller .

A good article for Action Helper is written by the Lead Mathew . You can read over http://devzone.zend.com/article/3350 .

Thanks harikt.

I was fooling around with them and discovered that — also discovered some differences — the book was not at all clear.

I’m not sure of the reason why they are seperated like that and why you might choose one over another (other than that action helpers are much better).

Is it possible to directly call a method in a view helper class?

I guess I also just want to know why you’d use one and not the other. My thinking is that in the future if I go back to a project, I’m going to have some things in views and somethings in actions and they’re going to be harder to find/work with.

One example:
I want to display the credit a customer has and the number of minutes that credit translates into based on their currency. If I use view helpers I can pass their balance and currency from the controller to the view and let it get converted there. But I have to create 1 view to format currency and 1 view to convert the credit to minutes.

If I use action helpers then I can use 1 helper (with multiple methods) but now I have to pass currency, credits, and minutes to the view.

Do you get where I’m coming from?

So you know the differences between view helper and action helper , so I think you can easily deal with it .

To make it more clear , lets take an example
You have a form with an action to indexAction() . After the form has been processed , you want to redirect to a success page. Lets think its successAction() . In these cases we are can use action helpers .
The main aim of view is to remove a huge amount of PHP from the view script . ie why we are running with MVC . Really talking we are dealing with VC :wink: ( When application logic is moved to C, ie fatty ) .
So the V is having less php code , and when we need to make some logic we can use the view helper . Some if() or something . It all depends on our logic :slight_smile: .

thanks harikt.
I suppose i’m starting to get it. I guess I just need some time in the Zend trenches – then I’ll start to figure out what needs to go where more specifically (by getting frustrated when I return to projects I suppose!)

Thanks for some more clarification.

:slight_smile: cool .