2012-12-17 96 views
1

有人可以幫助我與我的過濾器,他們似乎沒有被從數據庫中獲取數據。CGridview過濾器似乎並不奏效

認爲有CGridview

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid', 
'dataProvider'=>$model->search(), 
'filter'=>$model, 
'enablePagination'=>true, 
'pager'=>array(
    'maxButtonCount'=>'7', 
), 
'columns'=>array(
    array(
     'name'=>'bt_number', 
     'type'=>'raw', 
     'value'=>$model->bt_number, 

    ), 
    array(
     'name'=>'date_time', 
     'type'=>'raw', 
     'value'=>$model->date_time, 
    ), 
      array(
     'name'=>'broker', 
     'type'=>'raw', 
        'value'=>$model->broker, 
     'filter'=>Yii::app()->params['brokers'], 

    ), 
    array(
     'class'=>'CButtonColumn', 
     'template'=>'{view}{update}' 
    ), 
) 
)); 

型號的模型,我試圖打印出的一個搜索元素我は沒有什麼顯示

public function search() 
{ 
    // Warning: Please modify the following code to remove attributes that 
    // should not be searched. 

    echo "booker ".$this->broker;// exit; 
      //above only displays booker there is nothing in $this->broker 

    $criteria=new CDbCriteria; 

    $criteria->compare('bt_number',$this->bt_number); 
    $criteria->compare('sign',$this->sign,true); 
    $criteria->compare('fm_buys',$this->fm_buys,true); 
    $criteria->compare('fm_buys_amt',$this->fm_buys_amt,true); 
    $criteria->compare('against',$this->against,true); 
    $criteria->compare('bt_sett_date',$this->bt_sett_date,true); 
    $criteria->compare('bt_order_type',$this->bt_order_type,true); 
    $criteria->compare('date_time',$this->date_time,true); 
    $criteria->compare('dealer',$this->dealer,true); 
    $criteria->compare('rate',$this->rate,true); 
    $criteria->compare('broker',$this->broker,true); 
    $criteria->compare('recapped',$this->recapped,true); 
    $criteria->compare('settled',$this->settled,true); 
    $criteria->compare('sett_date',$this->sett_date,true); 

    return new CActiveDataProvider($this, array(
     'criteria'=>$criteria, 
    )); 
} 

控制器是沒有得到任何東西過濾之一從$ _GET變種

public function actionIndex() 
{ 
    $model=new BrokerTrades('search'); 
    $model->unsetAttributes(); // clear any default values 
    if(isset($_GET['BrokerTrades'])) 
     $model->attributes=$_GET['BrokerTrades']; 

    print_r($_GET) ; 
    $this->render('index',array(
     'model'=>$model, 
    )); 
} 

我不明白爲什麼這個過濾器不工作,請HEL頁。

回答

2

確保每個要篩選的字段設置爲安全模型中的規則。

public function rules(){ 
    return array(
    .. 
    array('bt_number,sign,fmbuys','safe','on'=>'search'), 
); 
} 

的屬性需要設置安全,以使該行的功能:

$model->attributes=$_GET['BrokerTrades'];

就包括所有你想第一個字符串中搜索的屬性,用逗號分隔。

看看是否有幫助的。