2016-05-10 66 views
0

這是我想要下載爲pdf的查看頁面。我的觀點鏈接:http://localhost/myproject/Applicant/1如何將yii視圖頁面轉換爲pdf並下載它?

enter image description here

我想在該頁面的右上角把下載PDF按鈕,當我點擊它,用戶配置文件應在PDF下載。我新來yii所以不知道該怎麼做,但通過搜索谷歌,我發現了一些擴展。

  • 警予,PDF
  • mpdf1

按照上面這些擴展,我把這些擴展在我protected/extension文件夾中。然後,這裏是我的主/ config文件..

'components'=>array(
    'user'=>array(
     // enable cookie-based authentication 
     'class' => 'WebUser', 
     'allowAutoLogin'=>true, 
     'returnUrl'=>'/site/index#login', 
     'loginUrl'=>array('/Applicant/login'), 
    ), 
    'ePdf' => array(
     'class'   => 'ext.yii-pdf.EYiiPdf', 
     'params'  => array(
      'mpdf'  => array(
       'librarySourcePath' => 'application.extensions.mpdf.*', 
       'constants'   => array(
        '_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'), 
       ), 
       'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder 
       /*'defaultParams'  => array(// More info: http://mpdf1.com/manual/index.php?tid=184 
        'mode'    => '', // This parameter specifies the mode of the new document. 
        'format'   => 'A4', // format A4, A5, ... 
        'default_font_size' => 0, // Sets the default document font size in points (pt) 
        'default_font'  => '', // Sets the default font-family for the new document. 
        'mgl'    => 15, // margin_left. Sets the page margins for the new document. 
        'mgr'    => 15, // margin_right 
        'mgt'    => 16, // margin_top 
        'mgb'    => 16, // margin_bottom 
        'mgh'    => 9, // margin_header 
        'mgf'    => 9, // margin_footer 
        'orientation'  => 'P', // landscape or portrait orientation 
       )*/ 
      ), 
     ), 
    ), 

我在ApplicantController

public function actionPDF() 
{ 
    $mPDF1 = Yii::app()->ePdf->mpdf(); 
    $mPDF1->WriteHTML($this->render('UserProfileView',true)); 
    $mPDF1->Output(); 
} 

我應該做的未來創造了這個動作?如何獲取該視圖文件上的按鈕,該文件鏈接到控制器操作以下載文件。

回答

0

您需要將表單提交給一個操作。

例如,在您看來:

<?php echo CHtml::button('Button Text', array('submit' => array('controller/action'))); ?> 

在這裏的按鈕將調用控制器的動作和執行什麼需要以行動來完成。

EDITED

如果我是正確的,要渲染保護/視圖/申請/ view.php這樣你就可以在側邊欄的鏈接添加到你的行動:

<?php 
/* @var $this ApplicantController */ 
/* @var $model Applicant*/ 

$this->breadcrumbs=array(
    'Applicant'=>array('index'), 
    $model->id, 
); 

$this->menu=array(
    array('label'=>'List Applicant', 'url'=>array('index')), 
    array('label'=>'Create Applicant', 'url'=>array('create')), 
    array('label'=>'Create PDF', 'url'=>array('PDF')), 

不要忘了在ApplicantController.php添加到規則:

public function accessRules() 
{ 
    return array(
     array('allow', // allow all users to perform 'index' and 'view' actions 
      'actions'=>array('index','view','PDF'), 
      'users'=>array('*'), 
+0

不知道你的意思是什麼,我沒有表格,我從數據庫表中獲取用戶信息,並在表格的視圖中顯示.. –

相關問題