2015-05-20 74 views
0

我只是想覆蓋類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\');">&nbsp;CustomFilter</span>', 
     ), 

然後它將出現以下錯誤

屬性「CDataColumn.headerFilter」未定義。

但是,如果我直接加在覈心文件這些變化CGridColumn.php在gii.widgets.grid那麼它工作正常,但我不希望在覈心文件來改變。

+0

不同於論壇的網站,我們不使用的[所以]參見「[應‘你好’,‘謝謝’標語「謝謝」,或者「任何幫助表示讚賞」,或簽名,和。稱呼從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-sa lutations被移除從 - 個)。順便說一句,它是「提前致謝」,而不是「先進感謝」。 –

+0

你沒有告訴GridView使用你的自定義列,所以它默認使用CDataColumn(它沒有headerFilter prop)。您應該在下面的答案中指定'class'。也許你應該指定完整的路徑,即''class'=>'ext.CGridColumnCustom','(或者你放置它的位置)。沿着這些線 – Viacheslav

+0

@snegostup我也試過''class'=>'CGridColumnCustom'',我在我的組件文件夾中添加了這個CGridColumnCustom.php。我是否需要將其放在擴展文件夾中? –

回答

1

嘗試做如下方式:

第一件事情(其實不知道,如果是相關的,但字「列」就完了命名CGridCustomColumn

其次,鑑於應該是這樣的然後:

'columns'=>array(
     array(
      'header' => 'CGridCustom', 
      'class' => 'CGridCustomColumn' 
      'value' => '$data->Name' 
      'type' => 'raw' 
     ), 
+0

它不起作用。 –