Yii 搜索过滤器不工作

Yii search filter is not Working

这是我的视图文件

.........

'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 后它显示了所有订单..

哪里出了问题?

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

检查这些代码,这是我正在使用的 (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'),
))
?>