I am using session .If user logout and he write url for profile page profile page should not open.it should directly redirect to login page.I did it .But i write the code in every controller.
<?php
class PendingListController extends Controller
{
public function actionIndex()
{
$login_id = Yii::app()->session['login_id'];
$type = yii::app()->session['type'];
if($login_id && $type=='A')
{
$messagemodel = new Student('search');
$messagemodel->unsetAttributes();
if(isset($_GET['Student']))
{
$messagemodel->attributes=$_GET['Student'];
}
$this->render('index', array('messagemodel'=>$messagemodel));
}
else
{
$this->redirect(array('/site/login'));
}
}
} // End Class
?>
this type of code i write in each controller .But i think this not a reuse ability of code.so i think i should create a component n write the code there.But i dont know how to do it can any one help me .with example .