-- etopian <[EMAIL PROTECTED]> wrote
(on Wednesday, 02 July 2008, 05:46 AM -0700):
> So my direction is fine, that's good! So it is architectually ok to have
> database queries inside a helper.

All the classic MVC diagrams show the view talking to the model; the
only stipulation is that the view should never _write_ to the model --
i.e., no inserts or updates.

> What I was also after, was how to put the query in the helper. If you have
> any pointers on that, it would be great. In the mean time I will try some
> solutions myself.

I'd use Zend_Db, and in particular, Zend_Db_Select, to do it:

    $select = $db->select();
    $select->from('cms_pages', array('id', 'parent_id'))
           ->where('id = ?', $id);
    $fnp = $db->fetchAll($select);

>From there, the logic remains the same as what you had, but you now have
the benefits of properly escaped parameters in your SQL, and code that
can theoretically work across multiple DB platforms.


> etopian wrote:
> > 
> > Hi,
> > 
> > I'm trying to move some functions from older applications to my Zend
> > Framework application. I assume I put these each in a seperate view
> > helper? 
> > Besides that, I have this function:
> > 
> > function findNumParents($id, $parents){
> >   $sql = "SELECT 
> >                id, 
> >                parent_id 
> >              FROM 
> >                cms_pages 
> >              WHERE id=".$id;
> >   $fnp = fmsq($sql, true);
> >   $parents++;
> >   if($id == $fnp['id']){
> >     if($fnp['parent_id']){
> >       return findNumParents($fnp['parent_id'], $parents);
> >     }
> >   }
> >   return $parents;
> > }
> > 
> > My question is, how can I make the query to the database inside a View
> > Helper? Or is that the wrong way to approach this?
> > 
> > 
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Recursive-database-query-in-View-Helper-tp18233806p18236693.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
> 

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to