Newbie Here

I’ve recently started using Yii. My question is how do you automatically point your website to the default login page created by the yiic command?

You have to redirect from your SiteController/actionIndex

e.g




public function actionIndex()

	{

		$this->redirect(array('/shop/products/index'));

	}



No, for the login page created by the yiic command use:




public function actionIndex()

{

    $this->redirect('/site/login');

}



However this will get you into trouble if the user is already logged in because it’s an infinite loop. A better way is:




public function actionIndex()

{

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

        $this->redirect('/site/login');

    else

    {

         // your regular index page code

    }

}



If the user should be redirected to the login page due to restriction on the action he/she is trying to access you could just set up AccessRules in your products controller and Yii would handle the redirect automatically.

Here’s an example




public function accessRules()

{

   return array(

	array('allow', 

              'actions' => array('index',),

	      'users' => array('@'),

        ),

	array('deny',  // deny all users

	      'users' => array('*'),

	),

   );

}



Yes, this is more elegant indeed but I think the OP wanted a “quick and dirty” solution. ;)

thank you very much guys!

I agree :rolleyes:

Thanks everyone, by the way is it possible to create a web app without using the yiic? I’m trying to re create what I’ve done with yiic but I’m encountering a page not found error