Php CListView的默认排序和可排序属性

Php CListView的默认排序和可排序属性,php,yii,Php,Yii,在我的ClistView中,我试图设置一个默认排序,并在视图中定义我的可排序属性。我已经走了这么远 在myactionIndex()中 在我的模型中 public function relations() { return array( '_state' => array(self::BELONGS_TO, 'State', 'state'), '_make' => array(self::BELONGS_TO,

在我的ClistView中,我试图设置一个默认排序,并在视图中定义我的可排序属性。我已经走了这么远

在my
actionIndex()中

在我的模型中

public function relations()
    {
        return array(
            '_state' => array(self::BELONGS_TO, 'State', 'state'),
            '_make' => array(self::BELONGS_TO, 'pMake', '', 
                            'foreignKey' => array('make_code'=>'make_code')),
        );
    }
在我看来

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'sortableAttributes'=>array(
        '_make' => 'Make',
        'store',
        'state',
    ),
));
我得到这个错误

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column '_make' in 'order clause'. The SQL statement executed was: SELECT * FROM `store_new` `t` WHERE make_code!="00" ORDER BY _make DESC LIMIT 10 

如何对表进行排序
pMake.make

在您的
actionIndex()中尝试此操作

然后

那么在你看来,

'sortableAttributes'=>array(
    'make' => 'Make', //you can call "make" base on 'attributes'=>array('make'=>array())
    'store',
    'state',
),

注释已测试。希望它能起作用。

您确定您的
存储\u new
表包含
\u make
列吗?列名是
make
,我使用了
\u make
,因此在视图中调用它时不会感到困惑。我这样叫它
$data->\u make->make
错了吗?顺便说一句
$data->\u make->make
在我看来效果很好,你可以使用\u make。make@YatinMistry我得到这个'CDbCommand未能执行SQL语句:SQLSTATE[42S22]:未找到列:1054未知列'\u make.make'在'order子句'中。执行的SQL语句是:选择*FROM
store\u new
t
WHERE make\u code=“00”订单由制造商制造说明限制10`
$criteria=new CDbCriteria(array(                    
                                'with' => array('_make'),  // join the _make relation you defined in your model into this query
                                'condition'=>'t.make_code!="00"',
                        ));
$dataProvider=new CActiveDataProvider('StoreNew', array(
                    'criteria'=>$criteria,
                    'sort'=>array(
                       'attributes'=>array(
                            'make'=>array(
                                'asc'=>'_make.make',
                                'desc'=>'_make.make DESC',
                            ),
                          '*', //if attributes contains a star ('*') element, the name will also be used to match against all model attributes.
                        )
                    ),
        ));
'sortableAttributes'=>array(
    'make' => 'Make', //you can call "make" base on 'attributes'=>array('make'=>array())
    'store',
    'state',
),