Code snippets for symfony 1.x


Refine Tags

Snippets tagged "propel objects"

object_select_tag related classes

When you use the object_select_tag you specify related_class=Author for example. This will return all Authors and use the __toString() method to display the author.

However how do you select a subset of Authors based on some criteria.

To do this you can create a new Peer class that extends your BaseAuthorPeer, for example LiveAuthorPeer.

class LiveAuthorPeer extends BaseAuthorPeer {
    public static function doSelect(Criteria $criteria, $con = null)
        $criteria = new Criteria();
        $criteria->add(AuthorPeer::IS_LIVE, 1);
        return AuthorPeer::doSelect($criteria);

You can the call this new class from you object_select_tag and it will return select options for only those authors with the value of IS_LIVE = 1.

<?php echo object_select_tag($books, 'getAuthorId', array (
  'related_class' => 'LiveAuthors'
)) ?>
by Alistair Stead on 2006-06-20, tagged forms  objects  propel