[英]Yii2: How to display search result without gridview in Yii2
Trying to implement search box for my page in which user has to enter job_code to get its order status. 尝试为我的页面实现搜索框,其中用户必须输入job_code才能获取其订单状态。 I'm getting result but this result in grid view I don't want this grid view. 我正在获取结果,但是此结果显示在网格视图中,我不需要此网格视图。 So, that I can place various attributes on page at different positions. 因此,我可以在页面上的不同位置放置各种属性。
Search form In which user has to enter job_code 搜索表单,用户必须在其中输入job_code
<?php $form = ActiveForm::begin(['action' => ['tracking'],'method' => 'get','class'=>'lockscreen-credentials']); ?>
<?= $form->field($searchModel, 'job_code')->textInput(array('placeholder' => 'Job Code..'))->label(false); ?>
<?= Html::submitButton('Search', ['class' => 'btn btn-primary btn-block btn-flat']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-primary btn-block btn-flat']) ?>
<?php ActiveForm::end(); ?>
Result Page on which Search Result will display 将在其上显示搜索结果的结果页面
<body class="lockscreen">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'job_code',
'client_code',
'company_name',
'job_description:ntext',
'status',
'emp_email:email',
'emp_mobile',
'emp_first_name',
'emp_last_name',
],
]); ?>
</body>
Controllers 控制器
public function actionIndex()
{
$model = new Status();
$searchModel = new StatusSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
]);
}
public function actionTracking()
{
$model = new Status();
$searchModel = new StatusSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('tracking', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
]);
}
How to achieve this? 如何实现呢?
You can access the data provider models data in this way 您可以通过这种方式访问数据提供者模型数据
for a dump result you don't need to format your code with html and limit the view to the first (or the only) line of data available. 对于转储结果,您不需要使用html格式化代码并将视图限制为可用数据的第一行(或唯一)。 Then for sample i use use only echo
然后我使用示例仅使用echo
<body class="lockscreen">
<?php
echo 'job_code = ' . $dataProvider->models[0]->job_code .' - ' ;
echo 'client_code = ' . $dataProvider->models[0]->client_code .' - ';
echo 'company_name = ' . $dataProvider->models[0]->company_name .' - ';
echo 'job_description = ' . $dataProvider->models[0]->job_description .' - ';
echo 'status = ' . $dataProvider->models[0]->status .' - ';
// and so on
</body>
I you need to show more then a row of data, you must obviously loop for all the models you prefer 我需要显示更多数据,然后再显示一行数据,显然必须为您喜欢的所有模型循环
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.