![]() |
|
Snippets |
|
Say that you have a model object Son that inherits from the model object Father, via propel inheritance. You want to create an admin generator interface for the object Son. The problem is that propel does not generate a SonPeer class, so you'll have to call:
symfony propel-init-admin Father
but the list function will list all the Father objects instead of the Son objects only. Same problem with the create function that will create a Father object, not a Son object.
Here is a solution. You will have to overload getFatherOrCreate and addFiltersCriteria:
// add this in the actions.class.php of your admin module protected function addFiltersCriteria(&$c) { $c->add(FatherPeer::CLASS_KEY, FatherPeer::CLASSKEY_SON); parent::addFiltersCriteria($c); } protected function getFatherOrCreate ($id = 'id') { $son = parent::getFatherOrCreate($id); if ($son->isNew()) // if it is a new one then we create a Son object $son = new Son(); else $this->redirect404Unless($son->isSon()); // we check that we really got a son object return $son; }
Now everything will work as if you were using the Son object.