yii CListView关系排序

时间:2014-06-28 21:16:26

标签: yii

目前,当我点击CListView生成表格中的排序时,它会将 MODEL_NAME_2 添加到网址

?page=1&sort=MODEL_NAME_2.cat.desc

有没有办法删除它?或者可能将其重命名为其他内容?或者这就是Yii的工作方式?

这是我的控制器中的actionIndex()

public function actionIndex()
{
    $dataProvider=new CActiveDataProvider('MODEL_NAME_1', array(
        'id'=> '', 
        'criteria' => array(
            'with' => 'MODEL_NAME_2',
            'together'=>true, //specifies whether the query should be run using a join
        ),
        'sort'=>array(
               'defaultOrder'=>'MODEL_NAME_2.cat ASC',
                'attributes'=>array(
                    'MODEL_NAME_2.cat'=>array(
                        'asc'=>'MODEL_NAME_2.cat',
                        'desc'=>'MODEL_NAME_2.cat DESC',
                    ),
                  '*',
                )
        ),
        'pagination'=>array(
            'pageVar'=>'page'
        )
    ));

    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}

在我看来

$this->widget('zii.widgets.CListView', array(
                    'dataProvider'=>$dataProvider,
                    'itemView'=>'_view', // refers to the partial view named '_view'
                    'enableHistory'=> true,
                    'sortableAttributes' => array('MODEL_NAME_2.cat'=>'Make'),
                    'pagerCssClass' => 'pagination',
                    'loadingCssClass' => '', //remove loading icon
                    'template'=>'
                        <div class="row">
                            <div class="col-md-12">
                                <div class="pull-left">{summary}</div>
                                <div class="pull-right">{sorter}</div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">{items}</div>
                        </div>',

                )); 

理想情况下,我希望我的网址看起来像这样

mysite.com/bla/page/2/sort/cat/desc

基本上使用了很多/而没有?&

1 个答案:

答案 0 :(得分:2)

在ListView定义中更改:

'sortableAttributes' => array('make'=>'Make'),

在您的dataProvider中

'sort'=>array(
               'defaultOrder'=>'MODEL_NAME_2.cat ASC',
                'attributes'=>array(
                    'make'=>array(
                        'asc'=>'MODEL_NAME_2.cat',
                        'desc'=>'MODEL_NAME_2.cat DESC',
                    ),
                  '*',
                )
        ),