This question already has an answer here:
- How to fix “Headers already sent” error in PHP 11 answers
im a yiibie. what i am trying to do is to get the role of the registered users and show them the content according to their role. i have two users right now
Admin
User(authenticared)
What i am doing is that when my admin logs in via user/login
the admin is redirected to the a page which is "webapp/story"
and a sidebarwidget is shown to the admin which i have already made and when the user(authenticated) gets logged in via "user/login"
that user is just redirected to index.php
.
after using the code to do this, when my admin gets logged it shows the error:
"Cannot modify header information - headers already sent by (output started at C:\wamp\www\emergency_response\protected\components\views\admin.php:73) "
I have used the code which is given below in and used this code in modules/user/controller/logincontroller.php
.
<?php
class LoginController extends Controller
{
public $defaultAction = 'login';
/**
* Displays the login page
*/
public function actionLogin()
{
if (Yii::app()->user->isGuest) {
$model=new UserLogin;
// collect user input data
if(isset($_POST['UserLogin']))
{
$model->attributes=$_POST['UserLogin'];
// validate user input and redirect to previous page if valid
if($model->validate()) {
$this->lastViset();
//this is the code which i have used for the task i am doing.
$role = Rights::getAssignedRoles(Yii::app() -> user -> Id);
foreach ($role as $role)
$role -> name;
if ($role -> name == 'Admin'){
$this->widget('AdminWidget') && $this->redirect(array('story'));
}
else{
$this->redirect(Yii::app()->user->returnUrl);
}
}
}
// display the login form
$this->render('/user/login',array('model'=>$model));
} else
$this->redirect(Yii::app()->controller->module->returnUrl);
}
private function lastViset() {
$lastVisit = User::model()->notsafe()->findByPk(Yii::app()->user->id);
$lastVisit->lastvisit = time();
$lastVisit->save();
}
}