Code snippets for symfony 1.x


Refine Tags

Snippets tagged "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 

Dump variables/objects to screen

Sometimes a set of circumstances will arise when the programmer is not certain what objects are available to a particular point of a symfony app (the manual is, at the time of writing, not entirely exhaustive).

Simply pop this code in your code temporarily and the output should give you some clues.

$vars = get_defined_vars();
foreach($vars as $key => $val) {
  $t = gettype($$key);
  echo "${key} (${t})<br />";
by halfer on 2006-06-02, tagged debug  objects  variables 
(1 comment)