2016-11-21 5 views
1

это мой взгляд файл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 он отображает все орды ers ..

где это пошло не так?

ответ

0

Проверить это код, это то, что я использую (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

даст попробовать –

0

Вы установили order_id как safe в модели.?

+0

да был установлен –