2016-11-07 3 views
1

actioncolumnのprictボタンをクリックすると、データを_printinvoiceページに渡します。この部分は正常に動作しています。今、ビューページに渡す直前にifステートメントが必要です。コンソールがGMの場合、私は_printinvoicegmに渡したいと思います。 _printinvoicesmに渡したい。私はコントローラのアクションで次のコードを試しました。このコードでyii2の場合のリダイレクト

public function actionPrintinvoice($id) { 

     $model = Bills::find()->where(['bills_ebillid' => $id])->one(); 
     $searchModel = new BillsSearch(); 
     $searchModel->console = $consoleid; 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $consoleid); 
     //$data   = Sellsg::findOne($id); 
     $searchModel1 = new ProductsalesSearch(); 
     $searchModel1->productsales_ebillid = $id; 
     $dataProvider1 = $searchModel1->search(Yii::$app->request->queryParams); 

     // $modelOffer = Offers::find()->orderBy('of_id')->limit(1)->one(); 
     // $searchModel2 = new OffersSearch();  
     // $dataProvider2 = $searchModel2->search(Yii::$app->request->queryParams); 

     if($consoleid == 'GM1' || $consoleid == 'GM2'){ 
      $content = $this->renderPartial('_printinvoicegm', [ 
      'model' => $model, 
      'dataProvider' => $dataProvider, 
      'searchModel' => $searchModel, 

      'searchModel1' => $searchModel1, 
      'dataProvider1' => $dataProvider1, 

      // 'modelOffer' => $modelOffer, 
      //'searchModel2' => $searchModel2,   
      //'dataProvider2' => $dataProvider2, 
      ]); 
     $footer = "<table name='footer' width=\"1000\"> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>GM</u></td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am to 9:00pm</td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">Friday Morning Closed</td>    
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">Prop:  M.Sinha</td> 
      </tr> 
     </table>"; 
     $pdf = new Pdf([ 
      'mode'=> Pdf::MODE_UTF8, 
      'format'=> Pdf::FORMAT_A4, 
      'destination'=> Pdf::DEST_BROWSER, 
      //'destination' => Pdf::DEST_DOWNLOAD, 
      'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
      // any css to be embedded if required 
      'cssInline' => '.kv-heading-1{font-size:18px}', 
      // set mPDF properties on the fly 
      'options' => ['title' => 'Print Invoice'], 
      //'options' => ['defaultfooterline' => 0,], 
      // call mPDF methods on the fly 
      'methods' => [ 
       //'SetHeader'=>['Amit Optical'], 
       'SetFooter'=>[$footer], 
      ], 
      'content' => $content, 

     ]); 

     }elseif($consoleid == 'SM1' || $consoleid == 'SM2'){ 
      $content = $this->renderPartial('_printinvoicegm', [ 
      'model' => $model, 
      'dataProvider' => $dataProvider, 
      'searchModel' => $searchModel, 

      'searchModel1' => $searchModel1, 
      'dataProvider1' => $dataProvider1, 

      // 'modelOffer' => $modelOffer, 
      //'searchModel2' => $searchModel2,   
      //'dataProvider2' => $dataProvider2, 
      ]); 
     $footer = "<table name='footer' width=\"1000\"> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>SM</u></td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am to 9:00pm</td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">Friday Morning Closed</td>    
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">Prop:  M.Sinha</td> 
      </tr> 
     </table>"; 
     $pdf = new Pdf([ 
      'mode'=> Pdf::MODE_UTF8, 
      'format'=> Pdf::FORMAT_A4, 
      'destination'=> Pdf::DEST_BROWSER, 
      //'destination' => Pdf::DEST_DOWNLOAD, 
      'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
      // any css to be embedded if required 
      'cssInline' => '.kv-heading-1{font-size:18px}', 
      // set mPDF properties on the fly 
      'options' => ['title' => 'Print Invoice'], 
      //'options' => ['defaultfooterline' => 0,], 
      // call mPDF methods on the fly 
      'methods' => [ 
       //'SetHeader'=>['Amit Optical'], 
       'SetFooter'=>[$footer], 
      ], 
      'content' => $content, 

     ]); 

     }elseif($consoleid == 'CN'){ 
      $content = $this->renderPartial('_printinvoicegm', [ 
      'model' => $model, 
      'dataProvider' => $dataProvider, 
      'searchModel' => $searchModel, 

      'searchModel1' => $searchModel1, 
      'dataProvider1' => $dataProvider1, 

      // 'modelOffer' => $modelOffer, 
      //'searchModel2' => $searchModel2,   
      //'dataProvider2' => $dataProvider2, 
      ]); 
     $footer = "<table name='footer' width=\"1000\"> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>CN</u></td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am to 9:00pm</td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">Friday Morning Closed</td>    
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">Prop:  M.Sinha</td> 
      </tr> 
     </table>"; 
     $pdf = new Pdf([ 
      'mode'=> Pdf::MODE_UTF8, 
      'format'=> Pdf::FORMAT_A4, 
      'destination'=> Pdf::DEST_BROWSER, 
      //'destination' => Pdf::DEST_DOWNLOAD, 
      'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
      // any css to be embedded if required 
      'cssInline' => '.kv-heading-1{font-size:18px}', 
      // set mPDF properties on the fly 
      'options' => ['title' => 'Print Invoice'], 
      //'options' => ['defaultfooterline' => 0,], 
      // call mPDF methods on the fly 
      'methods' => [ 
       //'SetHeader'=>['Amit Optical'], 
       'SetFooter'=>[$footer], 
      ], 
      'content' => $content, 

     ]); 

     } 


     return $pdf->render(); 
     //return $this->render('_printSalarystatement', ['s_period' => $s_period]); 

    } 

、私はエラーを取得しています -

Undefined variable: consoleid 

助けてください。

更新

public function actionPrintinvoice($id) { 

     $consoleid = 'My_console_id'; 
     $model = Bills::find()->where(['bills_ebillid' => $id])->one(); 
     $searchModel = new BillsSearch(); 
     $searchModel->console = $consoleid; 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 
     //$data   = Sellsg::findOne($id); 
     $searchModel1 = new ProductsalesSearch(); 
     $searchModel1->productsales_ebillid = $id; 
     $dataProvider1 = $searchModel1->search(Yii::$app->request->queryParams); 

     // $modelOffer = Offers::find()->orderBy('of_id')->limit(1)->one(); 
     // $searchModel2 = new OffersSearch();  
     // $dataProvider2 = $searchModel2->search(Yii::$app->request->queryParams); 
     if($consoleid == 'GM1' || $consoleid == 'GM2'){ 
      $content = $this->renderPartial('_printinvoicegm', [ 
      'model' => $model, 
      'dataProvider' => $dataProvider, 
      'searchModel' => $searchModel, 

      'searchModel1' => $searchModel1, 
      'dataProvider1' => $dataProvider1, 

      // 'modelOffer' => $modelOffer, 
      //'searchModel2' => $searchModel2,   
      //'dataProvider2' => $dataProvider2, 
      ]); 
     $footer = "<table name='footer' width=\"1000\"> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>GM</u></td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am to 9:00pm</td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">Friday Morning Closed</td>    
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">Prop:  M.Sinha</td> 
      </tr> 
     </table>"; 
     $pdf = new Pdf([ 
      'mode'=> Pdf::MODE_UTF8, 
      'format'=> Pdf::FORMAT_A4, 
      'destination'=> Pdf::DEST_BROWSER, 
      //'destination' => Pdf::DEST_DOWNLOAD, 
      'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
      // any css to be embedded if required 
      'cssInline' => '.kv-heading-1{font-size:18px}', 
      // set mPDF properties on the fly 
      'options' => ['title' => 'Print Invoice'], 
      //'options' => ['defaultfooterline' => 0,], 
      // call mPDF methods on the fly 
      'methods' => [ 
       //'SetHeader'=>['Amit Optical'], 
       'SetFooter'=>[$footer], 
      ], 
      'content' => $content, 

     ]); 
     return $pdf->render(); 
     }elseif($consoleid == 'SM1' || $consoleid == 'SM2'){ 
      $content = $this->renderPartial('_printinvoicesm', [ 
      'model' => $model, 
      'dataProvider' => $dataProvider, 
      'searchModel' => $searchModel, 

      'searchModel1' => $searchModel1, 
      'dataProvider1' => $dataProvider1, 

      // 'modelOffer' => $modelOffer, 
      //'searchModel2' => $searchModel2,   
      //'dataProvider2' => $dataProvider2, 
      ]); 
     $footer = "<table name='footer' width=\"1000\"> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>SM</u></td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am to 9:00pm</td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">Friday Morning Closed</td>    
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">Prop:  M.Sinha</td> 
      </tr> 
     </table>"; 
     $pdf = new Pdf([ 
      'mode'=> Pdf::MODE_UTF8, 
      'format'=> Pdf::FORMAT_A4, 
      'destination'=> Pdf::DEST_BROWSER, 
      //'destination' => Pdf::DEST_DOWNLOAD, 
      'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
      // any css to be embedded if required 
      'cssInline' => '.kv-heading-1{font-size:18px}', 
      // set mPDF properties on the fly 
      'options' => ['title' => 'Print Invoice'], 
      //'options' => ['defaultfooterline' => 0,], 
      // call mPDF methods on the fly 
      'methods' => [ 
       //'SetHeader'=>['Amit Optical'], 
       'SetFooter'=>[$footer], 
      ], 
      'content' => $content, 

     ]); 
     return $pdf->render(); 
     } 
     elseif($consoleid == 'CN'){ 
      $content = $this->renderPartial('_printinvoicecn', [ 
      'model' => $model, 
      'dataProvider' => $dataProvider, 
      'searchModel' => $searchModel, 

      'searchModel1' => $searchModel1, 
      'dataProvider1' => $dataProvider1, 

      // 'modelOffer' => $modelOffer, 
      //'searchModel2' => $searchModel2,   
      //'dataProvider2' => $dataProvider2, 
      ]); 
     $footer = "<table name='footer' width=\"1000\"> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>CN</u></td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am to 9:00pm</td> 
      </tr> 
      <tr> 
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">Friday Morning Closed</td>    
      <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">Prop:  M.Sinha</td> 
      </tr> 
     </table>"; 
     $pdf = new Pdf([ 
      'mode'=> Pdf::MODE_UTF8, 
      'format'=> Pdf::FORMAT_A4, 
      'destination'=> Pdf::DEST_BROWSER, 
      //'destination' => Pdf::DEST_DOWNLOAD, 
      'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
      // any css to be embedded if required 
      'cssInline' => '.kv-heading-1{font-size:18px}', 
      // set mPDF properties on the fly 
      'options' => ['title' => 'Print Invoice'], 
      //'options' => ['defaultfooterline' => 0,], 
      // call mPDF methods on the fly 
      'methods' => [ 
       //'SetHeader'=>['Amit Optical'], 
       'SetFooter'=>[$footer], 
      ], 
      'content' => $content, 

     ]); 
     return $pdf->render(); 
     } 
     //return $this->render('_printSalarystatement', ['s_period' => $s_period]); 

    } 

指数は以下のようになります - enter image description here

私はrespectiveprintページにリダイレクトするために印刷ボタンをクリックしています。 アクション列のコードは以下のようなものです - 今すぐ

[ 
      'class' => 'kartik\grid\ActionColumn', 
      'template' => '{update} {print}', 
      'buttons' => [ 
       'print' => function ($url, $model) { 
        return Html::a(
         '<span class="glyphicon glyphicon-print"></span>', 
         ['/invoice/bills/printinvoice', 'id' => $model->bills_ebillid,'cons' => $model->console ], 
         [ 
          'title' => 'Print', 
          'data-pjax' => '0', 
         ] 
        ); 
       }, 
       ], 
      ], 

、コンソールは、URLに渡しているが、私はそれに応じて別のページにリダイレクトするためにそれを使用することができませんよ。あなたはこの$のconsoleidが定義されていないが、あなたは

$searchModel->console = $consoleid; 

にアクセスしようとしているpreviosly適切な内容で定義されていないアサインのためのVARS

public function actionPrintinvoice($id) { 

    $model = Bills::find()->where(['bills_ebillid' => $id])->one(); 
    $searchModel = new BillsSearch(); 

//を使用している enter image description here

+0

を割り当てる必要があります

$model = Bills::find()->where(['bills_ebillid' => $id])->one(); 

を使用してこの情報をretrive。 '$ searchModel-> console'とは何ですか? –

答えて

1

使用する前に適切な値を定義してください。

例:

$consoleid = 'My_console_id' 

。 パブリック関数actionPrintinvoice($のID){

$consoleid = 'My_console_id' 
$model = Bills::find()->where(['bills_ebillid' => $id])->one(); 
$searchModel = new BillsSearch(); 

更新コメントが長すぎ

私は、エラーの理由は、変数その事実dovitaたことを通知するための$ consoleid =「My_console_id」をsettedています適切に割り当てられる前に使用されました。 :あなたのコードでは、選択するデータを検索するために使用されるパラメータにその値が割り当てられているという事実は残っています。このパラメータに割り当てられる正しい値が、有効な検索で何になるか分かりません。結果が得られず、空白のページが表示される理由があります。したがって、適切なデータを見つけて印刷を許可するため、アプリケーションが$ consoleidに割り当てられる必要がある有効な値を知っておく必要があります。これはまた、私の答えがあなたが報告した問題に対処したことを意味します..

printinvoceのコードを見ると、IDとコンソールとして渡します。

['/invoice/bills/printinvoice', 'id' => $model->bills_ebillid,'cons' => $model->console ], 

..あなたは、あなたが機能

public function actionPrintinvoice($id, $cons) { 
...... 

の署名を変更し、あなたが宣言されていないも `$のconsoleid`を定義しないので

$searchModel->console = $cons; 
+0

どうすれば定義できますか? – Tanmay

+0

私はこのvarの意味を知りません..あなたは単に宣言して値を詰めて定義しています..私は答えを更新しました..(あなたは適切なコンテンツを割り当てるためにevalする必要があります) – scaisEdge

+0

$ consoleid = 'My_console_id 'あなたが示したように$ searchModel-> console = $ consoleid;特定の行から変数$ consoleidにコンソールを渡そうとしています。私がそれを間違ってやっているのか、それをどうやって行うのか教えてください。私は更新中の質問に私の現在の状況を追加しました。今エラーはありませんが、actioncolumnの印刷ボタンをクリックすると空白のページが表示されます。私はURLにはidが渡されているが、consoleidの兆候はないことがわかります。これを行う方法を教えてください。 – Tanmay

関連する問題