MVC is a fairly new concept for me and I have just found myself doing something I am not quite sure would be considered 'a good practice'.
I have a controller User
(extending from CUserController
) that deals with all user relate actions. In this controller I have actionLogin
that deals with login requests. Now in the process of login I need to display 3 different pages according to situation:
- Login form (enter username/password).
- Error message (if user details match but account is marked as blocked).
- Login successful page (if any new messages are associate with the account).
So far I have deal with it like that:
public function actionLogin(){
... perform some operations ...
... determine which page to display and set $scenario accordingly ...
$this->render('login',array(
'scenario'=>$scenario
));
}
And then in login.php
(the view file):
... perform some common operations ...
switch($scenario){
case "login":
...display login...
break;
case "error":
... display error ...
break;
.. etc. ...
}
Now this makes my view file show in fact entirely different pages (although closely related).
Would it be better to split my view into different pages (e.g. login-form.php
,login-error.php
,login-success.php
) and render different ones in actionLogin
according to the situation or is what I currently do a good way of dealing with this?