I am new to Yii and OOP in general. I have installed yii and it’s behaving great so far. I decided to play around with it with the sole purpose to learn. What I am trying to do is prevent the login page from displaying if the user has already logged in. So after you login you can still call index.php?r=site/login and the login page would display asking for your user/pass no matter whether you are logged in or not. So what I did is in my login.php file (views/login.php) added the following logic:
....show login form
echo "You are already logged in!";
The above code works! However, I am not sure if I am following the MVC design pattern by adding the above logic in a view file. Can you please advise me if there is a better way to apply this logic rather than in the view file?
This works brilliant. Thanks so much. Another question I have:
Yii renders the login page by:
‘login’ - is the naming convention for the login.php file but I don’t understand the convention for the array(‘form’=>$form). $form is declared in the actionLogin but what is the convention for ‘form’(the key). If I change it to array(‘form1’=>$form) it won’t work. I searched for this all over but was unable to find the answer.