I would like to check the tbl “Is there are data exists?”. If the data isn’t exists at tbl I want to redirect to one page. How can I do without placing the same code at the actions of all controller?
if(Company::model()->exists() == false)
$this->redirect(array('site/create'));
If you want to have this logic run before every action of every controller you can override the
runmethod of the base controller class (usually this is namedController; you will find it inside theprotected/components/directory).Here’s an example of how to do it: