Question

I am using DataProvider to show some data. The data is related to shows in the theater. I want to show the shows which are "On Season" first and then the shows that are not on season. And all the shows should be ordered alphabetically. I tried to use CSort but I am getting an error. Here is my code:

$dataProviderFiaba = new CActiveDataProvider('Show',
                    array(
                        'criteria'=>array(
                            'condition'=>'show_type= '.Show::TYPE_FIABA,
                        ),
                        'sort'=>array(
                            'defaultOrder'=>'on_season', //TO SHOW THE ON SEASON SHOWS FIRST
                            'asc'=>'title', // TO ORDER ALPHABETICALLY
                        ),
                    ));

And the error is Property "CSort.asc" is not defined. So I think I am not using CSort with the correct format. What is the right way to do this kind of sorting?

Was it helpful?

Solution

You can only use "asc" in the context of attributes for CSort. For example: $mCSort->attributes = array('title'=>array('asc'=>'title', 'desc' => 'title DESC'));

To solve your sorting problem, the following should be sufficent though:

$dataProviderFiaba = new CActiveDataProvider('Show',
                    array(
                        'criteria'=>array(
                            'condition'=>'show_type= '.Show::TYPE_FIABA,
                            'order'=>'on_season, title'
                        ),
                    ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top