Zend Framework: Do I need view helpers for this?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Zend Framework: Do I need view helpers for this?

Post by someberry »

I have been starting to learn the Zend Framework these past couple of days, and was wondering if I need to use view helpers for the following:

My website contains lots of blocks which are located in different positions for all pages. Obviously I don't want to code this for all controllers or for each view. I want to, from the view, do something like this:

Code: Select all

<div>
    <div class="block"><?= $this->block1 ?></div>
    <div class="block"><?= $this->block2 ?></div>
    ....
</div>
The problem I have with using view helpers for this is that the helper will need to generate and return HTML, so it would look something like this:

Code: Select all

<?php
class Zend_View_Helper_MyHelper
{
    public function myHelper() {
        // Perform some logic here from the Model
        return "
            <h2>Block title</h2>
            <p>....</p>
            <p>....</p>
            ....";
    }
}
And that just doesn't look or sound right. So, how would I achive this? I have read through the view helpers section on Zend's documentation but am left rather scratching my head.

Thanks :)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Zend Framework: Do I need view helpers for this?

Post by Eran »

That's exactly the purpose of view helpers, to encapsulate repeating presentation logic in your application. I would suggest better names than block1, block2 though :wink:
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Re: Zend Framework: Do I need view helpers for this?

Post by someberry »

pytrin wrote:That's exactly the purpose of view helpers, to encapsulate repeating presentation logic in your application.
Hmm. Just seems a bit strange to me generating and returning HTML in the PHP, though. I would have expected more of a template file.
pytrin wrote:I would suggest better names than block1, block2 though :wink:
Hehe. Why of course.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: Zend Framework: Do I need view helpers for this?

Post by jmut »

chaitanya_alluri
Forum Newbie
Posts: 1
Joined: Wed May 28, 2008 4:13 am

Re: Zend Framework: Do I need view helpers for this?

Post by chaitanya_alluri »

hi any one please help me with the complete php code for capturing screen shot(ffmpeg) of a uploaded video file and viewing that video file in a bigger dimension by giving thumbnail option to view screen shot .
Post Reply