2011-03-07 48 views
1

我想在保存前取消设置一个场,正好通过SF产生的executeCreate()函数。我使用的是这样的:试图保存前取消设置一个字段,使用offsetUnset()

$this->configuration->getForm()->getWidgetSchema()->offsetUnset('clients'); 
var_dump($this->configuration->getForm()->getWidgetSchema()); 

但在那之后的场的 “客户” 仍然存在:

object(sfWidgetFormSchema)[180] 
    protected 'formFormatters' => 
    array 
     empty 
    protected 'fields' => 
    array 
     'id' => 
     object(sfWidgetFormInputHidden)[211] 
      protected 'parent' => 
      &object(sfWidgetFormSchema)[180] 
      protected 'requiredOptions' => 
      array 
       ... 
      protected 'attributes' => 
      array 
       ... 
      protected 'options' => 
      array 
       ... 
     'name' => 
     object(sfWidgetFormInputText)[212] 
      protected 'parent' => 
      &object(sfWidgetFormSchema)[180] 
      protected 'requiredOptions' => 
      array 
       ... 
      protected 'attributes' => 
      array 
       ... 
      protected 'options' => 
      array 
       ... 
     'clients' => 
     object(sfWidgetFormInputText)[184] 
      protected 'parent' => 
      &object(sfWidgetFormSchema)[180] 
      protected 'requiredOptions' => 
      array 
       ... 
      protected 'attributes' => 
      array 
       ... 
      protected 'options' => 
      array 
       ... 
     '_csrf_token' => 
     object(sfWidgetFormInputHidden)[203] 
      protected 'parent' => 
      &object(sfWidgetFormSchema)[180] 
      protected 'requiredOptions' => 
      array 
       ... 
      protected 'attributes' => 
      array 
       ... 
      protected 'options' => 
      array 
       ... 

任何想法?

SF 1.4

哈维

回答

0

你可以在表格类,方法配置未设置表单字段:

class ClientsForm extends BaseClientsForm 
{ 
    public function configure() 
    { 
     unset($this['field1'], $this['field2']); 
    } 
} 

这从表格中删除字段,并从保存这种形式

生成的SQL查询
相关问题