Hi everyone, I need some help to access the data retrieve from Active Records.
What I want to do is,
-
check login
-
retrieve userID
-
Check a Many to Many table(userReports model) between userID and ReportID to see which reports this user is authorized to view
-
Each report has parameters(parameters model)
So from the Users model, I have added a many many relation with userReports, and from reports, it has a Has Many relation with parameters.
Firstly I'll present the beautiful models.
class reports extends CActiveRecord
....
public function relations()
{
return array(
'userList'=>array(self::MANY_MANY, 'Users', 'userreports(userID,reportID)'),
'parameterList'=>array(self::HAS_MANY, 'Parameters', 'reportID'),
);
}
class parameters extends CActiveRecord
...
public function relations()
{
return array(
'report'=>array(self::BELONGS_TO, 'Reports', 'reportID')
);
}
In reportsController
$userID=user()->getState('userID');
$criteria=new CDbCriteria;
$criteria->condition='userID='.$userID;
$form = new ParameterForm;
$users=Users::model()->with(
'reportList',
'reportList.parameterList'
)->findAll($criteria);
When I print_r($users) I can see that all the information has been retrived from the database it's in one big array, but I'm stuck on how I should access, the columns from reports and also parameters?
I'll also need to perform a loop on the parameters to generate the appropriate fields.
Can anyone point me in the right directions? Thanks a lot!