Everything was working great in my application till I thought of using RBAC in the application. Below are the changes I made (till this point everything was working fine).
- Included authManager in main.php configuration file (as per the guide)
- Manaully imported auth SQL file (yii/framwork/web/auth/schema-mysql.sql) in database
- Finally executed the code below which got executed successfully as entries were created in auth tables.
$auth=Yii::app()->authManager;
$role = $auth->createRole('admin', 'administrator');
$auth->assign('admin',1); // adding admin to first user created
Right after this, everything stopped working and I get the error below.
[size="3"][color="#ff0000"]Trying to get property of non-object[/color][/size]
[size="2"]This error comes while trying to access $user object. One example mentioned below (error comes at $user access, line 6 below)[/size]
line1: $user = User::model()->findByPk($data->user_id);
line2: echo 'On ' . strftime('%m/%d/%Y at %I:%M %P', strtotime($data->created));
line3: echo ' - ';
line4: echo CHtml::link($data->category->name, array('story/category', 'category_id'=>$data->category_id));
line5: echo ' - ';
line6: echo ' by ' . $user->username . ' (' . CHtml::link($data->gender, array('story/gender', 'gender'=>$data->gender)) . ')';
Since then I have deleted all auth related tables and removed inclusion of authManager in main.php but to no avail. I am 100% sure the problem has started after enabling auth only since morning itself I was testing the application and it was working great.
Anyone aware of any known reason which could be responsible for this? Thanks!
<div><br></div><div><b>UPDATE</b>: Just noticed that both $data and $user objects are not null and have all information which is required in line 6 above. This makes matter more complicated. </div>