2016-05-10 7 views
0

これは私がpdfとしてダウンロードしたい私のビューページです。マイビュー・リンク:私は、そのページの右上部にあるダウンロードPDFボタンを配置することで、私をクリックするとhttp://localhost/myproject/Applicant/1yiiビューページをpdfに変換してダウンロードするには?

enter image description here

、ユーザープロファイルがPDFでダウンロードする必要があります。私はyiiの新しいので、それを行う方法がわからないが、Googleで検索すると、私はいくつかの拡張子を発見した。これら上記の拡張機能に従うことによって

  • の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

あなたは何を正確に意味するのかわかりません。私はフォームを持っていません。ユーザーのデータベーステーブルから情報を取得し、テーブルのビューページに表示しています。 –

関連する問題