Symfony1 addCSRFProtection在公用函数configure()中不工作

Symfony1 addCSRFProtection在公用函数configure()中不工作,symfony1,symfony-1.4,Symfony1,Symfony 1.4,当我应用此代码时: class ContactoForm extends BaseContactoForm { public function configure() { $this->addCSRFProtection(rand(1, 1000)); } } $this->form = new ContactoForm(); $this->form = new ContactoForm(); $this->form->a

当我应用此代码时:

class ContactoForm extends BaseContactoForm
{
    public function configure()
    {
        $this->addCSRFProtection(rand(1, 1000));
    }
}
$this->form = new ContactoForm();
$this->form = new ContactoForm();
$this->form->addCSRFProtection(rand(1, 1000));
然后我转到action.php模块:

class ContactoForm extends BaseContactoForm
{
    public function configure()
    {
        $this->addCSRFProtection(rand(1, 1000));
    }
}
$this->form = new ContactoForm();
$this->form = new ContactoForm();
$this->form->addCSRFProtection(rand(1, 1000));
该字段不会更改_csrf_令牌:

刷新1:

<input type="hidden" id="contacto__csrf_token" value="d6e64fcc34a99c1c90dd95eef945e564" name="contacto[_csrf_token]">
如果你换的话,给你

Refresh 1:
<input type="hidden" id="contacto__csrf_token" value="22815f44f18e41947d7568c0771abda4" name="contacto[_csrf_token]">

Refresh 2:
<input type="hidden" id="contacto__csrf_token" value="38bfae0a71a79d16b39ce943658f2700" name="contacto[_csrf_token]">

Refresh 3:
<input type="hidden" id="contacto__csrf_token" value="882c989dc95e40406b28200631cffc3d" name="contacto[_csrf_token]">
刷新1:
刷新2:
刷新3:
在symfony 1.2中,它起了作用。
现在symfony 1.4不起作用,请帮助我,谢谢。

我不能说我了解symfony,但从您的示例可以看出,在创建ContactoForm的新实例时,没有调用configure()。尝试在ContactoForm的构造函数中显式调用它

class ContactoForm extends BaseContactoForm {
    public function __construct() {
        parent::__construct();  // if there is a parent constructor
        $this->configure();
    }
    public function configure() {
        $this->addCSRFProtection(rand(1, 1000));
    }
}

configure
方法是从表单的
\u构造调用的@j0k是的,sfForm在它的_构造中调用configure(),但在没有看到ContactoForm中的实际代码的情况下,我们不知道该类中是否定义了_构造(),这将阻止调用父类,除非显式地这样做。@Joe是的,但通常您不会修改任何sfForm中的
\u__u构造
方法,而且,您不会修改基*表单类,因为它们是由条令/推进生成的。