Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Yii::app()->end() method and how is it different from exit()?

Tags:

php

exit

yii

In form validating,I find such codes

if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }

The manual says that the end() method will terminate the application. Why to terminate the app? The following codes will not execute?

like image 720
Chris Avatar asked May 14 '12 02:05

Chris


People also ask

What is Yii ::$ app?

Each Yii application system contains a single application object which is created in the entry script and is globally accessible through the expression \Yii::$app . Info: Depending on the context, when we say "an application", it can mean either an application object or an application system.

How to set header in yii2?

You can send HTTP headers by manipulating the header collection in the response component. For example, $headers = Yii::$app->response->headers; // add a Pragma header. Existing Pragma headers will NOT be overwritten.


1 Answers

Yes, it's an Ajax request and the code is supposed to return the validation results and then stop code execution. It's the same idea as the Php die function, but allows Yii to run onApplicationEnd cleanup code (if any)

like image 119
acorncom Avatar answered Sep 18 '22 19:09

acorncom