@Csrf()
注解,主要用于校验Csrf令牌是否有效。
场景:校验Csrf令牌是否有效。
支持:HTTP
注解:@Csrf()
参数:
type=""
get
、post
、raw
、header
post
name=""
csrf
clean=""
false
否、true
是true
tips=""
false
否、true
是一个完整的案例如下:
<?php
namespace app\http;
use x\controller\Http;
class Index extends Http
{
/**
* @RequestMapping(route="/index", method="get", title="主页")
* @Csrf(type="get", name="token", clean="true", tips="令牌错误")
*/
public function index() {
// Csrf令牌通过 get[token]提交上来
return $this->fetch('通过校验了');
}
/**
* @RequestMapping(route="/test", method="get", title="主页")
*/
public function test() {
// 这里生成Token到视图,然后放到表单里提交到index路由
return $this->fetch(csrf());
}
}
当校验不通过时,会回调到生命周期\box\lifecycle\csrf_error
类中进行处理。