在我的控制器中:
$model = new Sheets();
$criteria = new CDbCriteria;
$criteria->compare('id', $model->id);
$criteria->compare('track_name', $model->track_name, true);
$criteria->addCondition('user_id = '.Yii::app()->user->getId().' and '.$listSetups[$i]['condition']);
$setups = new CActiveDataProvider($model, array('criteria' => $criteria));
在我看来:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'sheets-grid',
'dataProvider' => $model,
//'filter' => $model,
'template'=>'{items}<div class="nav-controller">{pager}</div>',
'enableSorting' => false,
'columns' => array(
array(
'header' => 'Track',
'name' => 'track_name',
'value' => $model->track_name,
'htmlOptions' => array(
'width' => '135px',
),
),
但我得到这个错误:
错误:未定义属性“CActiveDataProvider.track_name”。
任何人都可以告诉我这是为什么?我该如何解决它。我不想使用$data->track_name
,因为我想在此代码中使用 $model->track_name 来自定义按钮“添加”:
array(
'header' => '',
'class' => 'CButtonColumn',
'template' => '<div class="wrapper-tools">{share}{facebook}{twitter}{download}{add}{update}{delete2}</div>',
'buttons'=>array (
'add' => array
(
'label'=>'Add favorite',
'imageUrl'=> (Users::model()->checkFavorite(Yii::app()->user->getId(), $model->track_name)) ? Yii::app()->themeManager->baseUrl."/default/images/favorite.png" : Yii::app()->themeManager->baseUrl."/default/images/favorite-disabled.png",
'url'=>'Yii::app()->createUrl("/sheets/", array("id"=>$data->id))',
'options' => array('id' => 'add-favorite', 'class' => 'admin-tools' ),
//'visible' => 'Users::model()->checkFavorite(Yii::app()->user->getId(), $data->id) == false',
),
),
'htmlOptions' => array(
'class' => 'admin-tools-2',
),
)
谢谢