I am trying to list items from a db using AR and viewData but I would like to call to getimage function in my PersonController to search pictures in a directory based on the id_person that should return the AR cListView.
Person::model()->id_person is not returning me the id_person that i expect but viewData is calling to the function perfectly.
public function getimage($idperson)
{
//options for findfiles
$options = array(
'level'=>0,
'include'=>array('.png','.jpg','.gif','.avi'),
'exclude'=>array('Thumbs.db'),
);
//finding files on the person directory
$files = CFileHelper::findFiles(realpath('./images/person/'.$idperson),$options);
return $files[0];
}
[color="#008000"]/* Moved from "Feature Requests" to "General Discussion for Yii 1.1.x" */[/color]
Hi ITDap,
CActiveRecord::model() returns the static model instance that we use to perform various queries. It’s not designed to be used like that, I mean, it will not return any correct person_id when you write “Person::model()->person_id”.
And, I guess your list view will display a list of Persons. Am I right? If so, then every list item should have a different person_id, that can be retrieved like “$data->person_id”. You’d better call your getImage function inside the partial view for the list view.