Simple question from a Yii Beginner

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);




	// collect user input data




		// validate user input and redirect to the previous page if valid

		if($model->validate() && $model->login())



	// display the login form



I have two questions:

  1. 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?

  2. 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.

  1. It takes info from the login form and tries to actually log user in. If it went fine then redirect is performed.

  2. Yes, it means exactly that. PHP is stateless in its nature when used in a "usual" way so it creates new application instance on each request.

Thanks. This helps.

Visit First These links gives best idea to understand MVC in Yii Framework and then Goes for other