在yii2中重定向if条件
单击actioncolumn中的prict按钮后,我想将数据传递到page\u printinvoice。这部分工作正常。现在,在传递到视图页面之前,我想要一个if语句。如果控制台是GM,我想传递给_printinvoicegm,如果控制台是SM。我想传给印刷发票。我在控制器操作中尝试了以下代码在yii2中重定向if条件,yii2,Yii2,单击actioncolumn中的prict按钮后,我想将数据传递到page\u printinvoice。这部分工作正常。现在,在传递到视图页面之前,我想要一个if语句。如果控制台是GM,我想传递给_printinvoicegm,如果控制台是SM。我想传给印刷发票。我在控制器操作中尝试了以下代码 public function actionPrintinvoice($id) { $model = Bills::find()->where(['bills_ebillid'
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]);
}
请帮忙
更新
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]);
}
公共函数actionPrintinvoice($id){
$consoleid='My_console_id';
$model=Bills::find()->where(['Bills\u ebillid'=>$id])->one();
$searchModel=新BillsSearch();
$searchModel->console=$consoleid;
$dataProvider=$searchModel->search(Yii::$app->request->queryParams);
//$data=Sellsg::findOne($id);
$searchModel1=新产品SalesSearch();
$searchModel1->productsales\u ebillid=$id;
$dataProvider1=$searchModel1->search(Yii::$app->request->queryParams);
//$modelOffer=Offers::find()->orderBy('of_id')->limit(1)->one();
//$searchModel2=新报价搜索();
//$dataProvider2=$searchModel2->search(Yii::$app->request->queryParams);
如果($consoleid=='GM1'| |$consoleid=='GM2'){
$content=$this->renderPartial(“打印发票”)[
'model'=>$model,
“dataProvider”=>$dataProvider,
“searchModel”=>$searchModel,
“searchModel1”=>$searchModel1,
'dataProvider1'=>$dataProvider1,
//“modelOffer”=>$modelOffer,
//“searchModel2”=>$searchModel2,
//'dataProvider2'=>$dataProvider2,
]);
$footer=”
转基因的
上午九时至晚上九时
星期五上午休息
道具:辛哈先生
";
$pdf=新pdf([
'mode'=>Pdf::mode_UTF8,
'format'=>Pdf::format_A4,
“目的地”=>Pdf::目的地浏览器,
//'destination'=>Pdf::DEST_下载,
“cssFile'=>”@vendor/kartik-v/yii2 mpdf/assets/kv mpdf bootstrap.min.css',
//如果需要,将嵌入任何css
'cssInline'=>'.kv-heading-1{font size:18px}',
//动态设置mPDF属性
“选项”=>[“标题”=>“打印发票”],
//'选项'=>['defaultfooterline'=>0,],
//动态调用mPDF方法
“方法”=>[
//“SetHeader”=>[“Amit光学”],
“SetFooter”=>[$footer],
],
“内容”=>$content,
]);
返回$pdf->render();
}elseif($consoleid=='SM1'| |$consoleid=='SM2'){
$content=$this->renderPartial(“打印发票”)[
'model'=>$model,
“dataProvider”=>$dataProvider,
“searchModel”=>$searchModel,
“searchModel1”=>$searchModel1,
'dataProvider1'=>$dataProvider1,
//“modelOffer”=>$modelOffer,
//“searchModel2”=>$searchModel2,
//'dataProvider2'=>$dataProvider2,
]);
$footer=”
性虐待
上午九时至晚上九时
星期五上午休息
道具:辛哈先生
";
$pdf=新pdf([
'mode'=>Pdf::mode_UTF8,
'format'=>Pdf::format_A4,
“目的地”=>Pdf::目的地浏览器,
//'destination'=>Pdf::DEST_下载,
“cssFile'=>”@vendor/kartik-v/yii2 mpdf/assets/kv mpdf bootstrap.min.css',
//如果需要,将嵌入任何css
'cssInline'=>'.kv-heading-1{font size:18px}',
//动态设置mPDF属性
“选项”=>[“标题”=>“打印发票”],
//'选项'=>['defaultfooterline'=>0,],
//动态调用mPDF方法
“方法”=>[
//“SetHeader”=>[“Amit光学”],
“SetFooter”=>[$footer],
],
“内容”=>$content,
]);
返回$pdf->render();
}
elseif($consoleid=='CN'){
$content=$this->renderPartial(“打印发票”)[
'model'=>$model,
“dataProvider”=>$dataProvider,
“searchModel”=>$searchModel,
“searchModel1”=>$searchModel1,
'dataProvider1'=>$dataProvider1,
//“modelOffer”=>$modelOffer,
//“searchModel2”=>$searchModel2,
//'dataProvider2'=>$dataProvider2,
]);
$footer=”
CN
上午九时至晚上九时
星期五上午休息
道具:辛哈先生
";
$pdf=新pdf([
'mode'=>Pdf::mode_UTF8,
'format'=>Pdf::format_A4,
“目的地”=>Pdf::目的地浏览器,
//'destination'=>Pdf::DEST_下载,
“cssFile'=>”@vendor/kartik-v/yii2 mpdf/assets/kv mpdf bootstrap.min.css',
//如果需要,将嵌入任何css
'cssInline'=>'.kv-heading-1{font size:18px}',
//动态设置mPDF属性
“选项”=>[“标题”=>“打印发票”],
//'选项'=>['defaultfooterline'=>0,],
//动态调用mPDF方法
“方法”=>[
//“SetHeader”=>[“Amit光学”],
“SetFooter”=>[$footer],
],
“内容”=>$content,
]);
返回$pdf->render();
}
//返回$this->render(“\u printSalarystatement',['s\u period'=>$s\u period]);
}
该索引如下所示-
我正在点击印刷品
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]);
}
[
'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',
]
);
},
],
],
public function actionPrintinvoice($id) {
$model = Bills::find()->where(['bills_ebillid' => $id])->one();
$searchModel = new BillsSearch();
$searchModel->console = $consoleid;
$consoleid = 'My_console_id'
$consoleid = 'My_console_id'
$model = Bills::find()->where(['bills_ebillid' => $id])->one();
$searchModel = new BillsSearch();
['/invoice/bills/printinvoice', 'id' => $model->bills_ebillid,'cons' => $model->console ],
$model = Bills::find()->where(['bills_ebillid' => $id])->one();
public function actionPrintinvoice($id, $cons) {
......
$searchModel->console = $cons;