Clistview ,active Record And Viewdata


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.

Have any idea ? Help will appreciate it.

<?php $this->widget('zii.widgets.CListView', array(





)); ?>

public function getimage($idperson)



			//options for findfiles

			$options = array(






			//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.

Yes my list will display persons, could you give me an example to call the function from a partial view ?

As you see in the reference, you can use $this to access the controller from the itemView partial view.

$image = $this->getImage($data->id_person);

echo CHtml::image($image);