Symfony forms: how to change default widget for form generation

后端 未结 2 1645
刺人心
刺人心 2021-02-06 16:23

I\'m using a custom Widget for date fields, and I want to use it in all my forms. The problem is that symfony uses the default sfWidgetFormDate. What I want is to change this de

2条回答
  •  被撕碎了的回忆
    2021-02-06 17:23

    Following johnwards answer, as I want to define default options for the widget, I also override the function to do that:

    class myFormGenerator extents sfDoctrineFormGenerator
    {
    
      public function getWidgetClassForColumn($column)
      { 
        ...
      }
    
      public function getWidgetOptionsForColumn($column)
      {
        switch ($column->getDoctrineType())
        {
          case 'date':
            return "array('config' => '{}', 'image'=>'/images/calendar.png')";
        break;
          default:
            return parent::getWidgetOptionsForColumn($column); 
        }
      }
    }
    

提交回复
热议问题