Hello,
I need to make a site, password pretected.
If (user is logged)
show site;
else
show loginForm;
where i must to put the code and what code.
Thanks.
Hello,
I need to make a site, password pretected.
If (user is logged)
show site;
else
show loginForm;
where i must to put the code and what code.
Thanks.
Hello izzi,
you should have a look at this chapter (Creating First Yii Application) of the yii guide.
If you need a more advanced authorization system, continue reading this chapter (Authentication and Authorization).
greets ironic
thanks but i know yii for about a month, i readed that more than 3 times, I need only a short answer at my small question, only the code and where to put it, not her explanation.
sorry for my english,
Quote
sorry for my english,
You were just given the answer to your 'small question'. Go read the scaffolding code. It's quite simple to understand.
A user authentication system isn't exactly a small thing although Yii takes a lot of the hard part out of it.
http://www.yiiframew…/prototype.auth
Contains the basics of what you need for an authentication system.
In your default action you could put something like this:
<?php if(Yii::app() -> user -> isGuest) { // redirect user to login form } else { // show the site }
But then you would need that in every controller / action I think.
Chris
Ok, thanks, I try to reformulate my question,
Where is that place in code, that is accesed on every page, to put there the redirection??
Please, answer concrete and do not tell me to read the documentation, beacase first i readed it and after that i posted this topic.
What kind of code? Class, method, view? You can try with widget.
Define a base controller class and override its init() method.
In this method, check if the user is logged in. If not, redirect him to the login page.
All you concrete controller classes should extend from this base class.
super
thanks, but where to put this file with derived class, in componnents directory ??
Yes, you can put this base class file under components directory so that you don't need to explicitly import/include it when you define concrete controller classes.
Sorry but how do you make a base controller?
for example:
class BaseController extends CController { public function init() { parent::init(); // your own code here } }
ok, thanks.
Quote
http://www.yiiframew…/prototype.auth
Contains the basics of what you need for an authentication system.
In your default action you could put something like this:
<?php if(Yii::app() -> user -> isGuest) { // redirect user to login form } else { // show the site }
But then you would need that in every controller / action I think.
Chris
What about action filters?