Login form as index page


I’ve used the search function, but with no luck…

I’m trying to do this in an elegant way.

What I want is a design similar to Gii - the user is prompted to login before being able to access the rest of the site. There will be also a ‘Create account’ link under the user name/password fields.

Now what my problem is: if I have a default controller (e.g. SiteController), should I use filters? Or override the beforeControllerAction method (that’s what Gii does)? Or should I have another controller just to handle the login view/form? Most of the examples I saw, have an index page with a Login/Logout menu entry - not what I’m looking for.

Please let me know your opinions :slight_smile:

Thanks in advance,


I think best solution for that is to use one of ready-to-use extesion in repository. Look here: http://www.yiiframework.com/extensions/?cat=1

After that, you can create a “parent” controller (for example MyController.php in ‘components’ direcotry) and then make other controllers extend MyController. In MyController, at last, you could use a filter to protect entire site access.




Thanks for your reply. I will look at the extensions, but as this is a uni project, I can’t rely heavily on not self-made code… :expressionless:

Anyway, there is the class Controller, which came in the extensions components directory (when my webapp was created with yiic). All other controllers inherit from this class. Would it be a good place to put the filter there?

Kind regards,


yes, if other controllers extends Controller. Remember only to something like this in child controllers:

public functions filters()


    return parent::filters();


In this way you inherit filters’access policy from parent controller.



Thanks :)

I’ll give that a try.

Kind regards,