I frequently pass full model instances through to my views and retrieve
information from them, but I don't write code in the models that is
specifically used for display purposes - as an example, if there's a method
calculateOutstandingBalance(), it's just going to return a float, it's the
exact same method and return value that I'd use if I called it from
somewhere else in the model. I would wrap the dollar sign around it and pad
it to two decimal places in the view though, because that's display logic.

I suppose the other option is to write controllers that simply list every
variable you're going to want to display and call the appropriate method to
fill their values, but that seems really dumb to me.

On Wed, Mar 31, 2010 at 6:58 AM, My Lists <l...@eduardocury.net> 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