【问题标题】:Symfony 1.4 embedRelation unset Field(s)Symfony 1.4 embedRelation 未设置字段
【发布时间】:2010-12-08 06:15:21
【问题描述】:

我在 embedRelation 的选项中看到您可以传递一个表单类,所以我假设我可以简单地设置一个新表单并根据需要对其进行修改,然后将其作为类传递给 embedRelation,瞧我的表单看起来/像我一样欲望。不是这样,我该怎么做!?

ma​​gicForm.class.php 中的示例:

function configure()
{
    $magicForm = new magicForm();
    unset($magicForm['fieldName']);
    $this->embedRelation('Magic',$magicForm);
}

我希望这会嵌入一个漂亮的表单减去“fieldName”字段,但事实并非如此,整个表单被嵌入而没有任何变化。

那么如何在嵌入表单之前自定义表单,而不是使用上面示例完美适用的 embedForm?

【问题讨论】:

    标签: forms symfony1 doctrine


    【解决方案1】:

    embedRelation 采用 Form 类的名称而不是表单本身的实例,然后它基本上完成了创建 tht 类实例并设置它的所有方法。如果您想在此之后修改表单,您需要通过访问各种架构对象来完成,例如:

    function configure()
    {
    
        $this->embedRelation('Magic','magicForm');
    
        unset($this['Magic']['fieldName']);
    
        $this->getEmbeddedForm('Magic')
          ->widgetSchema['anotherField']
          ->setOption('class', 'some_class');
       //etc..
    
    }
    

    为了它的价值,我从不使用嵌入关系......我只是用embedForm 来做你提到的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-29
      • 2011-06-07
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多