Where does this go? I’m not quite clear on where I would call this (or what needs to go in the widget when it is called). Would it go in the controller after the widget is defined? In the view as part of the definition of the datacontroller? As a subsequent call?
mdomba… would you mind elaborating on the array notation in the documentation. Since the documentation says that is for CSort and I can’t seem to figure out how I would call it for the CListView where I am trying to use it.
You have to set it on your dataprovider object. The default CRUD creates this in the search() method of your model. So you can set it either inside this method or on the data provider object which it returns (that’s what the first post here implies).
public function search()
/* ... your search criteria here ... */
return new CActiveDataProvider($this, array(
'defaultOrder'=> /* your default order here */
/* ... your sort attributes here ... */
Consider the data provider as the object which is also responsible for paginating and sorting of your data. It uses some other objects inside to achieve this. You should check out the manual of CActiveDataProvider.
I am a novice yii user and I have read this thread, tried the suggestions, and I am using 1.1.13 version of framework but I get a CException with message "Property "CListView.defaultOrder" is not defined.". What does this mean and how do I fix it? I am trying to display in my index view a list of events by order of eventDate attribute not the primary key as does now. This is my code so far
<?php $this->widget('zii.widgets.CListView', array(
'defaultOrder'=>array('eventDate'=>CSort::SORT_DESC,), //TRYING TO SORT THE LIST OF EVENTS
Is this where I should be editing or is it the loadModel() function in the controller?