admin generatorでできるだけ手抜きをするためのBaseFormFilterPropel と BaseFormPropelのテンプレ
frontendでも使ってたらNGぽいけど管理画面でしか使ってないので可能な限り手抜きをしたい
- lib/form/BaseFormPropel.class.php
<?php abstract class BaseFormPropel extends sfFormPropel { public function setup() { foreach ($this->getWidgetSchema()->getFields() as $name => $widget) { // formから消す if (in_array($name, array('created_at', 'updated_at', 'is_delete'))) { unset($this[$name]); } // 日本風 switch (get_class($widget)) { case 'sfWidgetFormDateTime': $widget->setOption('date', array('format' => '%year%年%month%月%day%日')); break; case 'sfWidgetFormDate': $widget->setOption('format', '%year%年%month%月%day%日'); break; default: // 何もしない break; } } } }
- lib/filter/BaseFormFilterPropel.class.php
<?php abstract class BaseFormFilterPropel extends sfFormFilterPropel { public function setup() { // 何故かデフォでついてないidを追加 if (!in_array('id', $this->getFields()) && !isset($this->widgetSchema['id'])) { $this->setWidget('id', new sfWidgetFormFilterInput(array('with_empty' => false))); $this->setValidator('id', new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false)))); } // 日本風 foreach ($this->getWidgetSchema()->getFields() as $name => $widget) { switch (get_class($widget)) { case 'sfWidgetFormFilterDate': $widget->getOption('from_date')->setOption('format', '%year%年%month%月%day%日'); $widget->getOption('to_date')->setOption('format', '%year%年%month%月%day%日'); break; default: // 何もしない break; } } } }