duannaiying9662
duannaiying9662
2015-07-18 13:50
浏览 131
已采纳

Yii2:如何在Yii2中显示没有gridview的搜索结果

Trying to implement search box for my page in which user has to enter job_code to get its order status. 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

<?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(); ?>

enter image description here

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>

enter image description here

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjiao2978
    duanjiao2978 2015-07-18 15:53
    已采纳

    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. Then for sample i use use only 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

    点赞 评论

相关推荐