我只是想覆盖类CGridColumn但不知何故它不覆盖。覆盖类的CGridColumn
我的代码是下面
<?php
Yii::import('zii.widgets.grid.CGridColumn');
class CGridColumnCustom extends CGridColumn
{
// new variable that will bind near header
public $headerFilter;
public function renderHeaderCell()
{
$this->headerHtmlOptions['id']=$this->id;
echo CHtml::openTag('th',$this->headerHtmlOptions);
$this->renderHeaderCellContent();
$this->renderFilterHeaderCellContent();
echo "</th>";
}
#------------------------------------------------------------------------------------
# custom function that will concat with renderHeaderCellContent at renderHeaderCell
#------------------------------------------------------------------------------------
protected function renderFilterHeaderCellContent()
{
echo trim($this->headerFilter)!=='' ? $this->headerFilter : $this->grid->blankDisplay;
}
}
?>
和i的组件文件夹添加文件(CGridColumnCustom.php)和i也导入该文件在文件CustomerModule.php像下面
$this->setImport(array(
'customer.components.*',
));
但是当我试图实现我的自定义功能,如下所示查看文件
'columns'=>array(
array(
'name' => 'Name',
'value' => '$data->Name',
'type' => 'raw',
'headerFilter'=> '<span class="name-filter-head" onclick="alert(\'test\');"> CustomFilter</span>',
),
然后它将出现以下错误
属性“CDataColumn.headerFilter”未定义。
但是,如果我直接加在核心文件这些变化CGridColumn.php在gii.widgets.grid那么它工作正常,但我不希望在核心文件来改变。
不同于论坛的网站,我们不使用的[所以]参见“[应‘你好’,‘谢谢’标语“谢谢”,或者“任何帮助表示赞赏”,或签名,和。称呼从帖子中删除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-sa lutations被移除从 - 个)。顺便说一句,它是“提前致谢”,而不是“先进感谢”。 –
你没有告诉GridView使用你的自定义列,所以它默认使用CDataColumn(它没有headerFilter prop)。您应该在下面的答案中指定'class'。也许你应该指定完整的路径,即''class'=>'ext.CGridColumnCustom','(或者你放置它的位置)。沿着这些线 – Viacheslav
@snegostup我也试过''class'=>'CGridColumnCustom'',我在我的组件文件夹中添加了这个CGridColumnCustom.php。我是否需要将其放在扩展文件夹中? –