我在index2.php
文件中有3个字段和一个按钮。这些不是来自任何模型。我需要传递字段作为参数并调用控制器动作stockbetweendates。出于某种原因,我不想使用javascript
或ajax
。我怎么能只用yii2
代码呢?
index2.php
<div class="sellitem-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<div class="row">
<div class="form-group">
<div class="col-xs-4 col-sm-4 col-lg-4">
<label for="upc" class="control-label"><p class="text-info">Product Code <i class="icon-star"></i></p></label>
<input type="text" class="form-control" id="upc" class="span3">
</div>
<div class="col-xs-4 col-sm-4 col-lg-4">
<label for="upc" class="control-label"><p class="text-info">Start Date <i class="icon-star"></i></p></label>
<?= DatePicker::widget([
//'label' => 'Startdate',
'name' => 'startdate',
'id' => 'startdate',
//'value' => '02-16-2012',
'template' => '{addon}{input}',
'clientOptions' => [
'autoclose' => true,
'todayHighlight' => true,
'format' => 'yyyy-mm-dd'
]
]);?>
</div>
<div class="col-xs-4 col-sm-4 col-lg-4">
<label for="upc" class="control-label"><p class="text-info">End Date <i class="icon-star"></i></p></label>
<?= DatePicker::widget([
//'label' => 'Startdate',
'name' => 'enddate',
'id' => 'enddate',
//'value' => '02-16-2012',
'template' => '{addon}{input}',
'clientOptions' => [
'autoclose' => true,
'todayHighlight' => true,
'format' => 'yyyy-mm-dd'
]
]);?>
</div>
</div>
<div class="col-xs-4 col-sm-4 col-lg-4">
<label for="desc" class="control-label"><p class="text-info">Product Desc <i class="icon-star"></i></p></label>
<input type="text" class="form-control" id="desc" class="span3">
</div>
</div>
<p>
<div class="form-group pull-right">
<button id="yourButton" class="btn btn-primary" >Seach</button>
</div>
</p>
</div>
控制器操作
public function actionStockbetweendates($productname, $startdate, $enddate) {
$modelProduction = Puritem::find()->where(['pi_upc' => $productname]);
$searchModel1 = new PuritemsbSearch();
$dataProvider1 = $searchModel1->search(Yii::$app->request->queryParams, $productname);
$modelSell = Sellitem::find()->where(['si_iupc' => $productname]);
$searchModel2 = new SellitemsbSearch();
$dataProvider2 = $searchModel2->search(Yii::$app->request->queryParams, $productname);
$content = $this->renderPartial('_printproductledgerbtdt', [
'modelProduction' => $modelProduction,
'dataProvider1' => $dataProvider1,
'searchModel1' => $searchModel1,
//'data'=> $data,
'modelSell' => $modelSell,
'searchModel2' => $searchModel2,
'dataProvider2' => $dataProvider2,
'productname' => $productname,
//'prodesc' => $prodesc,
]);
$footer = "<table name='footer' width=\"1000\">
<tr>
<td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">Signature</td>
</tr>
</table>";
$pdf = new Pdf([
'mode'=> Pdf::MODE_UTF8,
'format'=> Pdf::FORMAT_A4,
'destination'=> Pdf::DEST_BROWSER,
'orientation'=> Pdf::ORIENT_LANDSCAPE,
//'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 Party Ledger'],
//'options' => ['defaultfooterline' => 0,],
'options' => ['defaultheaderline' => 0,],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['Ledger'],
//'SetFooter'=>[$footer],
],
'content' => $content,
]);
return $pdf->render();
}
更新 我试图从表单中调用控制器操作并尝试下面的操作 -
<div class="sellitem-form">
<?php $form = Html::beginForm([
'id' => 'form-id',
'method' => 'get',
'action' => ['/stock/sellitem/printproductledger2']
]); ?>
<div class="row">
<div class="form-group">
<div class="col-xs-2 col-sm-2 col-lg-2">
<?= Html::input('text', 'productname', $productname->productname, ['class' => $productname]) ?>
</div>
</div>
</div>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-success']) ?>
</div>
<?php Html::endForm(); ?>
</div>
我收到Undefined offset: 0
错误。
答案 0 :(得分:0)
您可以使用GET方法,因此,您可以从控制器中的URL获取参数值。
$form = ActiveForm::begin([
'id' => 'form-id',
'method' => 'get',
]);
echo $form->field($Model, 'field1');
echo $form->field($Model, 'field2');
echo $form->field($Model, 'field3');
echo Html::submitButton('Find', ['class' => 'btn btn-primary']);
ActiveForm::end();