The example warns about calling action() which has to clone half the
dispatch process, dispatch a new action, grab the response body and return
it.  Obviously that's a pretty expensive call.  That said, I have to agree
with the commenter.  You could get a similar result with:

class My_View_Helper_BugList extends Zend_View_Helper_Abstract
{
    public function bugList(Bug $model)
    {
        // ...
    }
}

// In your controller
$this->view->bug = new Bug();

// In your view
$this->butList($this->bug);

That way your view (and view helper) only handle the display logic and the
controller handles passing the model to the view.

CM

  <http://cmorrell.com/> *Chris Morrell*  Web: http://cmorrell.com  Twitter:
@inxilpro <http://twitter.com/inxilpro>


On Tue, Mar 30, 2010 at 6:58 PM, My Lists <[email protected]> wrote:

> Hello people, check out this example found at :
>
> http://framework.zend.com/manual/en/performance.view.html
>
>
> class My_View_Helper_BugList extends Zend_View_Helper_Abstract
> {
>     public function bugList()
>     {
>         $model = new Bug();
>         $html  = "<ul>\n";
>         foreach ($model->fetchActive() as $bug) {
>             $html .= sprintf(
>                 "<li><b>%s</b>: %s</li>\n",
>                 $this->view->escape($bug->id),
>                 $this->view->escape($bug->summary)
>             );
>         }
>         $html .= "</ul>\n";
>         return $html;
>     }
> }
>
>
> I like the approach to attach the Model inside view helper for
> specific stuff and reusability. Im right now needing a helper exactly
> like this but i dont know if i'm violating any pattern rule.
>
> One guy as commented out about above example that this is a bad
> practive since the view shouldn't know the model. What do you think
> about this ? Should i go ahead in the same way?
>
> I have read in many places that this is pretty acceptable in the MVC,
> just wanted to confirm this.
>
> Thanks,
>
>

Reply via email to