2014-04-15 67 views
0

我正在嘗試從已過濾的CGridView創建PDF。該值將通過高級搜索下拉列表中傳遞,但問題是我無法通過我的pdf函數篩選搜索。從已過濾的CGridView創建PDF文檔 - Yii

控制器

public function actionPrint() { 
    $mPDF1 = Yii::app()->ePdf->mpdf('ar','A4','14','dejavusanscondensed'); 
    $model=new Country('search'); 

    $model->center_id = 1;// This value will be passed from dropdown 
          //and i want the report to be made on this 

    $model->unsetAttributes(); 
    if(isset($_GET['Country'])) 
     $model->attributes=$_GET['Country']; 

    $html = ''; 
    $html .= $this->renderPartial('candidates', array('model'=>$model, 'enablePagination' => false),true); 
    $mPDF1->WriteHTML($html, false); 
    $mPDF1->Output('list.pdf','D'); 
} 

查看

$this->widget('zii.widgets.grid.CGridView', array(
     'id'=>'country-grid', 
     'dataProvider'=>$model->search($enablePagination), 
     'summaryText' => '', 
     // 'enablePagination' => false, 
     'filter'=>$model, 
     'columns'=>array(
      'name', 
      array(
       'header'=>' Total Registered Candidates', 
       'value'=>'$data->itemsTotal', 
      ), 
     ), 
    )); 
    echo CHtml::link(
     'Save as PDF', 
     Yii::app()->createUrl('country/print'), 
     array('class'=>'btnPrint btn btn-danger','target'=>'_blank')); 

模型

public function search($enablePagination = true) 
{ 
     $criteria->together= true; 
     $criteria->with=array('center'); 
$criteria->compare('center.name', $this->center_id, true); 
.......... 
     if ($enablePagination) 
     { 
       $pagination = array(
         'pageSize' => 30, 
       ); 
     } 
     else 
     { 
       $pagination = false; 
     } 

     return new CActiveDataProvider($model, array(
       'criteria' => $criteria, 
       'pagination' => $pagination, 
     )); 
} 
+0

打印按鈕/鏈接?如果是的話,傳遞的鏈接參數是什麼?這可能是因爲您沒有將過濾器值作爲參數傳遞。 – topher

+0

@topher問題不是傳遞值,因爲您可以看到我硬編碼了值,儘管這樣我無法獲得過濾的PDF報告。 –

+0

您正在使用'$ model-> unsetAttributes()'取消設置'center_id'。將'$ model-> center_id = 1;'移動到'$ model-> attributes = $ _GET ['Country'];' – topher

回答

1

由於center_id是一個外鍵行

$criteria->compare('center.name', $this->center_id, true); 

應該讀

$criteria->compare('center_id', $this->center_id); 

你也可以做到以下幾點,但是這增加了對連接表的條件,並可能導致更慢的查詢。

$criteria->compare('center.id', $this->center_id);