1. <i id='37pDw'><tr id='37pDw'><dt id='37pDw'><q id='37pDw'><span id='37pDw'><b id='37pDw'><form id='37pDw'><ins id='37pDw'></ins><ul id='37pDw'></ul><sub id='37pDw'></sub></form><legend id='37pDw'></legend><bdo id='37pDw'><pre id='37pDw'><center id='37pDw'></center></pre></bdo></b><th id='37pDw'></th></span></q></dt></tr></i><div id='37pDw'><tfoot id='37pDw'></tfoot><dl id='37pDw'><fieldset id='37pDw'></fieldset></dl></div>
  2. <legend id='37pDw'><style id='37pDw'><dir id='37pDw'><q id='37pDw'></q></dir></style></legend>
    <tfoot id='37pDw'></tfoot>
    • <bdo id='37pDw'></bdo><ul id='37pDw'></ul>
    1. <small id='37pDw'></small><noframes id='37pDw'>

      Yii2 ListView 和数据提供者

      时间:2023-10-16
        <tbody id='lVrK5'></tbody>

        • <legend id='lVrK5'><style id='lVrK5'><dir id='lVrK5'><q id='lVrK5'></q></dir></style></legend><tfoot id='lVrK5'></tfoot>

          <i id='lVrK5'><tr id='lVrK5'><dt id='lVrK5'><q id='lVrK5'><span id='lVrK5'><b id='lVrK5'><form id='lVrK5'><ins id='lVrK5'></ins><ul id='lVrK5'></ul><sub id='lVrK5'></sub></form><legend id='lVrK5'></legend><bdo id='lVrK5'><pre id='lVrK5'><center id='lVrK5'></center></pre></bdo></b><th id='lVrK5'></th></span></q></dt></tr></i><div id='lVrK5'><tfoot id='lVrK5'></tfoot><dl id='lVrK5'><fieldset id='lVrK5'></fieldset></dl></div>

          <small id='lVrK5'></small><noframes id='lVrK5'>

            • <bdo id='lVrK5'></bdo><ul id='lVrK5'></ul>
                本文介绍了Yii2 ListView 和数据提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                哪些数据必须发送给数据提供者?

                What data must be sended to dataprovider?

                在我的控制器中:

                public function actionIndex() {
                    $searchModel  = new UserSearch();
                    $dataProvider = $searchModel->search( Yii::$app->request->queryParams );
                //other stuff and sending array of params to view
                

                在视图中:

                echo ListView::widget( [
                    'dataProvider' => $dataProvider,
                ] );
                

                但我只有身份证:

                如果我设置了单个视图,例如:

                And if i`m set single view like:

                'itemView' => '_single',
                

                如何将数据发送到_single.php?

                how send data to _single.php ?

                我的意思是 - 需要像 GridView 这样的视图列表项的默认模板:

                I mean - need default template for view list items like in GridView:

                GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel' => $searchModel,
                    'columns' => [
                        ['class' => 'yiigridSerialColumn'],
                
                        'id',
                        'username',
                        'email:email',
                        'password',
                        'role',
                //....
                

                然后我得到了完美的网格:

                And then i got perfect grid:

                推荐答案

                Controller - SiteController.php

                <?php
                
                // Yii2 Listview Example : by Songwut Kanchanakosai, Thailand.
                
                use commonmodelsMembers;
                use commonmodelsSearchMembers;
                ...
                
                public function actionIndex() {
                    $searchModel = new SearchMembers();
                    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
                
                    return $this->render('index', [
                        'searchModel' => $searchModel,
                        'dataProvider' => $dataProvider,
                    ]);
                ?>
                

                查看 (1) - index.php

                <?php
                use yiiwidgetsListView;
                ...
                echo ListView::widget( [
                    'dataProvider' => $dataProvider,
                    'itemView' => '_item',
                ] ); ?>
                

                查看 (2) - _item.php

                <?php
                use yiihelpersHtml;
                ?>  
                
                <?=$model->name;?> 
                <?=$model->age;?> 
                <?=$model->mobile;?>
                

                示例结果:

                Songwut 36 +668-3949-5153
                Prawee  41 +668-7323-2334
                Kosol   32 +668-8014-0165
                Utehn   39 +668-7874-5643
                

                这篇关于Yii2 ListView 和数据提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:尝试使用带有 Yii2 接收类的 PHP DateTime 类未找到错误 下一篇:在 Yii2 应用程序中设置全局语言值

                相关文章

                <i id='YRUno'><tr id='YRUno'><dt id='YRUno'><q id='YRUno'><span id='YRUno'><b id='YRUno'><form id='YRUno'><ins id='YRUno'></ins><ul id='YRUno'></ul><sub id='YRUno'></sub></form><legend id='YRUno'></legend><bdo id='YRUno'><pre id='YRUno'><center id='YRUno'></center></pre></bdo></b><th id='YRUno'></th></span></q></dt></tr></i><div id='YRUno'><tfoot id='YRUno'></tfoot><dl id='YRUno'><fieldset id='YRUno'></fieldset></dl></div>

                <small id='YRUno'></small><noframes id='YRUno'>

                1. <legend id='YRUno'><style id='YRUno'><dir id='YRUno'><q id='YRUno'></q></dir></style></legend>

                    • <bdo id='YRUno'></bdo><ul id='YRUno'></ul>
                    <tfoot id='YRUno'></tfoot>