Page 1 of 1

Zend Framework: Do I need view helpers for this?

Posted: Mon May 26, 2008 11:23 am
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 :)

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

Posted: Mon May 26, 2008 2:08 pm
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:

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

Posted: Mon May 26, 2008 4:15 pm
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.

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

Posted: Wed May 28, 2008 1:53 am
by jmut

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

Posted: Wed May 28, 2008 4:18 am
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 .