나는 3 개의 필드와 버튼을 index2.php
파일에 넣었습니다. 이들은 어떤 모델도 아닙니다. 필자는 필드를 매개 변수로 전달하고 컨트롤러 작업 인 스톡 베이트를 호출해야합니다. 특정 이유로 인해 javascript
또는 ajax
을 사용하고 싶지 않습니다. yii2
코드로 어떻게해야합니까?버튼으로 컨트롤러 동작 호출 yii2에서 javascript없이 클릭
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();
}
업데이트 I 양식에서 컨트롤러의 액션을 호출하려고하고 아래에 노력하고있어 -
<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>
나는를 얻고 있습니다.오류.
당신은 그 괜찮 –
데이터를 제출 양식을 사용할 수 있습니다. 하지만 텍스트 상자에서 데이터를 가져 와서 컨트롤러에 매개 변수로 전달하려면 어떻게해야합니까? 컨트롤러 동작에서 매개 변수를 전달해야합니다. – Tanmay
3 필드가 모델입니다. 간단한 Yii2 url ::을 param과 함께 사용할 수 있습니다 ... – scaisEdge