//請(qǐng)求token
protected $token;
//請(qǐng)求控制器模型
protected $model;
//當(dāng)前請(qǐng)求對(duì)象
protected $request;
/**
* 該方法會(huì)在請(qǐng)求前調(diào)用
*/
public function beforeAction(Request $request)
{
$this->request = $request;
$model = str_replace('controller', 'model', str_replace('Controller', '', $request->controller));
if (class_exists($model)) {
$this->model = new $model;
}
$this->token = $request->post('token');
}
我在base控制器中這樣寫(xiě)的