I am new to php and Yii but have experience with OOP. I went through the process of setting up the same application as shown in the screencasts. While looking through how the M, V and C interact with each other I came upon this code in the SiteController.php of the demo application and had a question about it:
/**
* Displays the login page
*/
public function actionLogin()
{
$model=new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
[b]
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
[u]$this->redirect(Yii::app()->user->returnUrl);[/u]
}[/b]
// display the login form
$this->render('login',array('model'=>$model));
}
I have two questions:
-
What is this code which is in bold doing? Is it trying to find out whether the user is already logged in, and if he/she is, then redirecting it to the URL he/she was earlier at?
-
When i looked up the function definition for redirect method on the CController, it has an optional parameter $terminate which is set to true by default. Does that mean that once the user is redirected to the URL, the application will terminate? That does not make sense to me.
Hope you can help. Thanks.