Yii::$app->end();不明白这是干啥用的(这是一段邮箱找回密码的代码) [ 2.0 版本 ]
class ManageController extends Controller
{
public function actionMailchangepass()
{
$this->layout = false;
$time = Yii::$app->request->get("timestamp");
$adminuser = Yii::$app->request->get("adminuser");
$token = Yii::$app->request->get("token");
$model = new Admin;
$myToken = $model->createToken($adminuser, $time);
if ($token != $myToken) {
$this->redirect(['public/login']);
Yii::$app->end();
}
if (time() - $time > 300) {
$this->redirect(['public/login']);
Yii::$app->end();
}
if (Yii::$app->request->isPost) {
$post = Yii::$app->request->post();
if ($model->changePass($post)) {
Yii::$app->session->setFlash('info', '密码修改成功');
}
}
$model->adminuser = $adminuser;
return $this->render("mailchangepass", ['model' => $model]);
}
}
最佳答案
其他 5 个回答
-
/** * Terminates the application. * This method replaces the `exit()` function by ensuring the application life cycle is completed * before terminating the application. * @param integer $status the exit status (value 0 means normal exit while other values mean abnormal exit). * @param Response $response the response to be sent. If not set, the default application [[response]] component will be used. * @throws ExitException if the application is in testing mode */
这是注释。意思就是end()为确保程序的生命周期的完成。
Tinywan 觉得很赞 -
liuxiajun828 回答于 2016-09-01 12:09 举报
看到源码是这么写,exit 终止执行,楼上的都是正确 也可以换成: die; return;
public function end($status=0,$exit=true)
{ if($this->hasEventHandler('onEndRequest')) $this->onEndRequest(new CEvent($this)); if($exit) exit($status); }
38311 觉得很赞
lzw 湖南
注册时间:2012-08-03
最后登录:2018-05-21
在线时长:9小时1分
最后登录:2018-05-21
在线时长:9小时1分
- 粉丝4
- 金钱800
- 威望10
- 积分990