Can we use more than one controller to handle different tabels. Like User controller to handle all the User create and updates and site controller before logon…?
What I am trying to do is that … there is two controller UserController and SiteContoller … when user is not logged on … the SiteController would redirect to site/index.html … When the user is logged on… the SiteController would redirect all request to page site/index.html to user/index.html…
How we have to accomplish this … is it by changing the urlpath or url manager in application or from sitecontroller actionindex…?
In Yii there is a default controller id. When you do redirect you can either specify controller/action or just action. When specify only action such as
Yii will redirect you to the default controller/user. By default the default controller is site hence with the above redirection you will be taken to site/user. In order to redirect to a specific controller you have to explicitly declare it in the redirect method such as
and this will take you to controller User / action Index
To do this, create a new controller in gii for the page your user will be directed to after s/he logs in. I’ll call this controller ‘app’. You’ll now have a file /protected/models/AppController.php
In this file, you will have a default public function (method) called actionIndex. The purpose of this default method is to call (render) the /protected/views/app/index.php file. That is the file your users will see once they log in. That is the file you will want to modify. Go back to SiteController.php and change the argument of redirect() in the actionLogin() method
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
// since my controller is /protected/controllers/AppController.php