![]() |
|
Snippets |
|
This is a very usefull and simple tip if you want to defined default value in edit form (only on creation of a new record) with the value that the user defined in the list filter.
An exemple for a product module which define the category select field with the value of the same field in the list filter.
action.class.php
public function executeEdit () { $filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/product/filters'); if (!$this->getRequestParameter('product_id', 0) && isset($filters['category_id'])) { $this->product = new Product(); $this->produit->setCatergoryId($filters['category_id']); } parent::executeEdit(); } protected function getProductOrCreate ($product_id = 'product_id') { if (isset($this->product)) return $this->product; else return parent::getProductOrCreate($product_id);
Comments on this snippet
This is a great thing. Very user friendly to support that.
change: protected function getProductOrCreate ($product_id = 'product_id') to: protected function getProductOrCreate ($product_id = 'id')
else: the getProductOrCreate method of the overloaded actions.class.php always runs into a "new" statement.