User Login Page as a start

Hi Folks,

i want to code a small "intranet" page. For this to accomplish i need a user login form to be displayed at first in the center of the screen when a visitor enters the site.

After login the main page should be displayed.

The approach i took is to add a second layout next to "main" called "login" where the login page is displayed.

Now come the questions:

  • how do i route the user from any place of the intranet to the login page, when he logs out or the session runs out?

approach: in the /components/Controller.php i added the init() method:

function init() {

		if (!Yii::app()->user->isGuest) {

			$this->layout = 'main';

		} else {

			$this->layout = 'login';



would this be a good approach?

  • should i use the SiteController for Login or should i use a seperate LoginController?

  • i need to instantiate the /models/LoginForm.php whenever the loginform has to be displayed - how can this be accomplished?

Thanks so much in advance, any help is appreciated!

If you have any good tutorial on this, please let me know!

Merry X-mas,


check out this post

and merry xma to you too :)