Yii的搜索过滤器不工作

Yii的搜索过滤器不工作

问题描述:

,这是我的看法文件Yii的搜索过滤器不工作

......... 

'dataProvider'=>$model->search(), 
'filter'=>$model, 
'columns'=>array(
    array(
      'header' => 'Order ID', 
      'name' => 'order_id', 
      'type' => 'raw', 
      'value' => 'Order::getorderid($data->order_id)', 
     ), 
    ), 
)); 

这是搜索功能我的文件Controller.php这样的文件

public function actionSearch() 
{ 
    $model = new Order('search'); 
    $model->unsetAttributes(); // clear any default values 
    if(isset($_GET['Order'])) { 
     $model->attributes = $_GET['Order']; 
     //echo "pre"; print_r($_GET); exit; 
    } 
    $this->render('search',array(
     'model'=>$model, 
    ));  
} 

这是模型file.php

public function search() 
{ 
    $criteria=new CDbCriteria;  
    $criteria->select='t.*'; 
    $criteria->compare('t.order_id',$this->order_id,true); 
    $criteria->compare('t.payment_firstname',$this->payment_firstname,true); 
    $criteria->compare('t.telephone',$this->telephone,true); 
    $criteria->compare('t.email',$this->email,true); 
    $criteria->compare('t.payment_address_1',$this->payment_address_1,true); 
    $criteria->compare('t.tracking_id',$this->tracking_id,true); 
    $criteria->join = 'left join order_product op on op.order_id =  t.order_id where t.order_type IN (3) group by t.order_id'; 
    $criteria->together = true; 
    return new CActiveDataProvider($this, array(
    'criteria'=>$criteria, 
    'sort'=>array(
     'defaultOrder'=>'order_id DESC', 
    ), 
    'pagination'=>array(
      'pageSize' => 40, 
     ), 
    )); 
} 

我在控制台中看不到任何错误.. $ _GET正在返回确切的字段,但在搜索到order_id后,它将显示所有ord Ers ..

哪里出错了?

检查这些代码,这就是我使用(DB:在PostgreSQL)

控制器

public function actionEstimate() 
    { 
     $model=new SalesEstimate(); 
       $model->unsetAttributes(); 
       if(isset($_GET['SalesEstimate'])) 
       { 
        $model->setAttributes($_GET['SalesEstimate']); 

       } 
       $this->render('estimate', array('model'=>$model)); 
    } 

型号

public function search() 
    { 
     $command =Yii::app()->db->createCommand("SELECT COUNT(*) FROM sp_sales_estimate_search(:enquiry_id,:ref_no,:estimate_date,:property_id,:amount,:status)"); 
     $command->bindParam(":enquiry_id",$this->enquiry_id,PDO::PARAM_STR); 
     $command->bindParam(":ref_no",$this->ref_no,PDO::PARAM_STR); 
     $command->bindParam(":estimate_date",$this->estimate_date,PDO::PARAM_STR); 
     $command->bindParam(":property_id",$this->property_id,PDO::PARAM_STR); 
     $command->bindParam(":amount",$this->amount,PDO::PARAM_STR); 
     $command->bindParam(":status",$this->status_search,PDO::PARAM_STR); 
     $count=$command->queryScalar(); 

     $sql="SELECT * FROM sp_sales_estimate_search(:enquiry_id,:ref_no,:estimate_date,:property_id,:amount,:status)"; 

     $dataProvider=new CSqlDataProvider($sql, array(
     'params' => array(':enquiry_id' => $this->enquiry_id,':ref_no' => $this->ref_no,':estimate_date' => $this->estimate_date,':property_id' => $this->property_id,':amount' => $this->amount,':status' => $this->status_search), 
     'totalItemCount'=>$count, 
     'db'=>Yii::app()->db, 
     'sort'=>array(
     'attributes'=>array(
      'ref_no','estimate_date','property_id','amount','status_search' 
     ), 
     ), 
     'pagination'=>array(
     'pageSize'=>10, 
     ), 
     )); 
     return $dataProvider; 
    } 

查看

<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'estimate-grid', 
    'itemsCssClass'=>'table table-bordered table-condensed table-hover table-striped dataTable', 
    'filter'=>$model, 
    'dataProvider'=>$model->search(), 
    'enablePagination' => true, 
     'enableHistory'=>true, 
    'pagerCssClass'=>'dataTables_paginate paging_bootstrap table-pagination', 
    'pager' => array('header'=>'','htmlOptions'=>array('class'=>'pagination')), 
    'columns' => array(

         array(name=>'ref_no','value'=>'$data["ref_no"]','header'=>'Ref No','htmlOptions'=>array('style'=>'text-align:right;width:5%')), 
      array(name=>'estimate_date','value'=>'Yii::app()->dateFormatter->format("dd/MM/yyyy",$data["estimate_date"])','header'=>'Date'), 

      ), 
      'htmlOptions'=>array('class'=>'grid-view table-responsive'), 
)) 
?> 
+0

会试一试 –

您是否在模型中将order_id设置为safe

+0

是的,它已经被设置 –