2016-08-25 18:42:17 9326次浏览 6条回答 1 悬赏 10 金钱
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]);

    }
}

最佳答案

  • 回答于 2016-08-26 12:59 举报

    redirect不能终止程序 必须使用return 或者 Yii::$app->end(); 终止程序

    , , , 觉得很赞
  • 回答于 2016-08-26 15:00 举报
    /**
         * 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()为确保程序的生命周期的完成。

    觉得很赞
  • 回答于 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);  
    }  
    
    觉得很赞
  • 回答于 2016-09-12 10:38 举报

    上一句已经跳转到其他页面了,想知道如果没有这一句会发生什么

    2 条回复
    回复于 2016-09-12 11:52 回复

    如果跳转是在方法末尾,就没关系,如果后面还有代码,而又没有终止,那就不会跳转,继续往下执行

    回复于 2016-09-12 11:55 回复

    自己试验了一下是这样的,感谢回复!

    , 觉得很赞
  • 回答于 2016-11-11 23:54 举报

    学习了,原来是相当于exit()。终止程序执行。

您需要登录后才可以回答。登录 | 立即注册
lzw
主管

lzw 湖南

注册时间:2012-08-03
最后登录:2018-05-21
在线时长:9小时1分
  • 粉丝4
  • 金钱800
  • 威望10
  • 积分990

热门问题