我有一个带有CGrideView的管理页面,但是当我想要更改按钮列以添加其他按钮时,会出现以下错误: CButtonColumn及其行为没有名为"getId“的方法或闭包。
管理员操作:
public function actionAdmin()
{
$model=new Block('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Block'])) {
$model->attributes=$_GET['Block'];
}
$this->render('admin',array(
'model'=>$model,
));
}管理员视图:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'block-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'name',
'content',
'type',
'enable',
array(
'class'=>'CButtonColumn',
'template' => '{view}{update}',
'buttons' => array(
'update' => array(
'url' => 'Yii::app()->controller->createUrl("update", array("name"=>$data->name))'
),
'view' => array(
'url'=>'CController::createUrl("view", array("name"=>$data->name))'
),
),
),
)));发布于 2015-08-15 19:27:01
解决了!原因在于:
'view'=>array(
'url'=>'CController::createUrl("view",array("name"=>$data->name))'
),它应该是:
'view'=>array(
'url'=>'Yii::app()->controller->createUrl("view", array("name"=>$data->name))'
),为什么呢?因为():因为Yii::app()->controller,它是当前应用程序的实例控制器。控制器具有私有$_id属性。CController::createUrl它只是一个静态方法。在方法中,createUrl()调用方法$this->getId(),但是当你调用静态方法时,实例并没有被创建-@DanilaGanchar。
因此,在CController::createUrl中,它找不到控制器的id,为了使用,我应该像这样给它提供参数CController::createUrl("/page/view",array("name"=>$data->name))我现在尝试了一下,并工作了
发布于 2015-08-15 18:38:21
template中元素的顺序必须与buttons中元素的顺序相同。您已经将{view}{update}作为template,但是您首先定义了update按钮!所以我认为把'template'=>'{view}{update}'改成'template'=>'{update}{view}'或许可以解决你的问题。
https://stackoverflow.com/questions/32023125
复制相似问题