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

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 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器