当然也可以使用配置里面完全把CSRFProtection关闭。
当我们使用symfony自带的sfGuardPlugin的时候。会自动生成登录验证页面。
默认情况下,页面中会有一个默认的参数叫_csrf_token的提交。
现在我们这边需要做个页面,但是不需要_csrf_token这个参数。
我们需要更改form,关闭CSRFProtection.
我们打开BasesfGuardFormSignin.class.php页面。

 

 
  
  1. class BasesfGuardFormSignin extends BaseForm 
  2.   
  3.   public function setup() 
  4.   { 
  5.    //在页面中加入这一行,就能关闭CSRFProtection了。这样登录页面就没有_csrf_token了。 
  6.     $this->disableCSRFProtection(); 
  7.     $this->setWidgets(array
  8.       'username' => new sfWidgetFormInputText(), 
  9.       'password' => new sfWidgetFormInputPassword(array('type' => 'password')), 
  10.       'remember' => new sfWidgetFormInputCheckbox(), 
  11.     )); 
  12.  
  13.     $this->setValidators(array
  14.       'username' => new sfValidatorString(), 
  15.       'password' => new sfValidatorString(), 
  16.       'remember' => new sfValidatorBoolean(), 
  17.     )); 
  18.  
  19.     if (sfConfig::get('app_sf_guard_plugin_allow_login_with_email', true)) 
  20.     { 
  21.       $this->widgetSchema['username']->setLabel('用户名'); 
  22.       $this->widgetSchema['password']->setLabel('密码'); 
  23.       $this->widgetSchema['remember']->setLabel('记住我'); 
  24.     } 
  25.  
  26.     $this->validatorSchema->setPostValidator(new sfGuardValidatorUser()); 
  27.  
  28.     $this->widgetSchema->setNameFormat('signin[%s]'); 
  29.   }