1
我有一個帶有字段和按鈕的搜索表單。在按鈕上單擊我要搜索2 searchmodel - sellitembtdtSearch
和puritembtdtSearch
。結果將顯示在一個視圖中。我可以毫無問題地顯示視圖。問題是,當我只搜索一個searchmodel正在搜索。請讓我知道如何在同一時間搜索searchModel。yii2中單個字段的兩個模型搜索中的兩個gridview
首先我登陸index2.php頁面,在那裏的表單是。
'action' => ['/stock/sellitem/printproductledger3',],
'method' => 'get',
<?= $form->field($model, 'productname')->textInput(['maxlength' => true,]) ?>
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
actionIndex2.php
public function actionIndex2()
{
$searchModel1 = new SellitemsbdtSearch();
$dataProvider1 = $searchModel1->search(Yii::$app->request->queryParams);
$searchModel2 = new PuritemsbdtSearch();
$dataProvider2 = $searchModel2->search(Yii::$app->request->queryParams);
return $this->render('_formbtdt', [
'model' => $searchModel2,
//'searchModel1' => $searchModel2,
]);
}
public function actionPrintproductledger3() {
$searchModel1 = new SellitemsbdtSearch();
$dataProvider1 = $searchModel1->search(Yii::$app->request->get());
$searchModel2 = new PuritemsbdtSearch();
$dataProvider2 = $searchModel2->search(Yii::$app->request->get());
//$productname = yii::$app->request->get('productname');
//$prodesc = yii::$app->request->get('prodesc');
$content = $this->renderPartial('_printproductledgerbtdt', [
//'productname' => $productname,
'searchModel1' => $searchModel1,
'dataProvider1' => $dataProvider1,
'searchModel2' => $searchModel2,
'dataProvider2' => $dataProvider2,
//'prodesc' => $prodesc,
]);
return $this->render('_printproductledgerbtdt', [
'dataProvider1' => $dataProvider1,
'searchModel1' => $searchModel1,
'searchModel2' => $searchModel2,
'dataProvider2' => $dataProvider2,
]);
此代碼僅searchs puritemdtdtSearch
。我想同時搜索puritembtdtSearch
和sellitembtdtSearch
。謝謝。
你有沒有考慮過使用ajax?你是什麼意思,你需要搜索不同的searchModels ...你可以只搜索1 searchModel,如果他們是相關的使用關係 –
是的。這裏 - http://stackoverflow.com/questions/41900399/display-pdf-in-browser-by-calling-controller-action-by-ajax-in-yii2 ... – Tanmay
他們有一個共同的領域,但因爲我想要顯示兩個單獨的gridview,我想構建單獨的搜索模型。 – Tanmay