DataProvider




$order_item = new OrderItem;

$order_item = $order_item->findByPK(2);

			

$order_item = new CActiveDataProvider($order_item, array(

	"pagination" => array(

	"pageSize" => 5

	)

));



I have this code, but why does it display all the records and not just the record with ID = 2?

I am putting this into a CListView wiget by the way.

I am trying to achieve pagination, sorting and views of my record using my "Models". I know I can just use the "criteria" option but I am trying to do it using my "Models". Can this done?

It does not matter if the final solution does not use the DataProvider.

The reason is that if you pass a model class to CActiveDataProvider it will try to create new instances of the class passed to the __construct (http://www.yiiframework.com/doc/api/1.1/CActiveDataProvider#__construct-detail) and then it builds the resulting dataset upon the criteria passed. What you did is actually the same as CActiveDataProvider(‘OrderItem’);

If you wish to display just a certain records with your CActiveDataProvider you are doing it the wrong way… use its criteria instead (config parameter)

Yeah I think it would be better if the CListView just allowed people to accept model objects then the CActiveDataProvider is not needed.

The only reason I am using the DataProvider, is because its the only thing that works with CListView.

I wish there was a way to do pagination, sorting and use CListView with just ordinary model objects but it does not seem like this is possible at the present time using the default functionality of Yii.