Symfony Howto: Call a variable Propel method
For Propel objects, you know how to call the class methods and constants:
$c = new Criteria(); $c->add(ItemPeer::PRICE, $price); $items = ItemPeer::doSelect($c);
But what if the class or the constant name are variable? The call_user_func() and constant() PHP functions will help you:
public function doSelect($class, $column, $value)
{
$class = get_class(call_user_func(array(new $class, 'getPeer')));
$column = strtoupper($column);
$c = new Criteria();
$c->add(constant($class.'::'.$column), $value);
$results = call_user_func(array($class, 'doSelect'), $c);
return $results;
}
$items = doSelect('Item', 'price', $price);