Hi,
I am new to Yii. I have four models with the following relation.(please see the ER Diargam)
1420
relations() in model ‘Role’ is:
return array(
'user'=>array(self::HAS_MANY, 'User', 'id_role'),
'rolePermissions'=>array(self::HAS_MANY, 'RolePermissions', 'id_role','with'=>'permissions'),
);
relations() in model ‘RolePermissions’:
return array(
'permissions' => array(self::BELONGS_TO, 'Permissions', 'id_permissions'),
'role' => array(self::BELONGS_TO, 'Role', 'id_role'),
);
relations() in model ‘Permissions’:
return array(
'rolePermissions'=>array(self::HAS_MANY, 'RolePermissions', 'id_permissions'),
);
relations() in model ‘User’:
return array(
'organisation' => array(self::BELONGS_TO, 'Organisation', 'id_organisation'),
'role' => array(self::BELONGS_TO, 'Role', 'id_role',
'with'=>'rolePermissions'),
);
I have successfully printed the role of each user from $data array(‘value’=>’$data[\‘role\’][\‘attributes\’][\‘name\’]’,) But I am unable to print the value of permissions field from permissions table.
print_r($dataProvider->data[2][‘role’][‘rolePermissions’]) This print statement will show the permission field value.
When I tried to print the value of permission in the following way, it returned an error ‘Undefined index: permissions’
‘value’=>’$data[\‘role\’][\‘rolePermissions\’][\‘permissions\’][\‘attributes\’][\‘permission\’]’,
Please help me to solve this issue.