Zend_View_Helper vs Zend View Partial Script

This is my fork in the road.

I want to show some button on my web page, and I want to do it in many places. This 'button' will really act as a link to some other page, and all button instances are going to go to one page.

I want all the buttons to be the same, with the possible exception of the size that they are.

Now, do I need to use a partial script with html for the button and call the helper part helper for rendering, or do I need to create a Zend_View_Helper that will return the html for the button when I call it?

I know that I can swing anyway, but what do you think is better?

Some things I see:

  • The helper may be better because it does not need to create a BIG object, for example, clone Zend_View for partial.

  • A partial script will make it easier for an html person to work with.

+6
zend-framework zend-view
source share
3 answers

Use $ this-> render () instead of $ this-> partial ().

Use only partial parts when you need more control over the area. As you said, it has a lot of overhead since it has to create a new instance of Zend_View. Using render does not work.

To address my actual question, I recommend using a render (or partial) on the view helper, because it is much simplified for working with projects and less costly. View helpers for custom features.

A good rule of thumb is whether you want to enable content / html or want to generate content / application transformations. Helpers for the latter.

+9
source share

Based on your description, I would suggest using partial for my task. The reason is because your button seems to be mostly html, without a lot of php. You could pass the size in partial, and that would be so. However, if you want to include more logic in the generation of your button (e.g. databases, auth or acl requests), I would suggest a view helper.

ps The third option would be to use both partial and auxiliary representations, perhaps not for this particular case, but in a more general sense. You can have an assistant that does part of php, and this helper call partially returns the desired html.

+1
source share

I tend to use the view helper anytime I need very parameterized values. For example:

echo $this->button('Button Text', '/foo/bar/baz'); 

It looks much better than:

 $this->buttonText = 'Button Text'; $this->buttonUrl = '/foo/bar/baz'; echo $this->render('button.phtml'); 

Also, there is no reason why you cannot display the script view from your view helper.

+1
source share

All Articles