【问题标题】:Why my filter arrayhelper not showing value from database yii2?为什么我的过滤器数组助手没有显示来自数据库 yii2 的值?
【发布时间】:2017-08-04 15:36:14
【问题描述】:

在视图/索引文件中显示我使用的模型的所有数据

'filter'=>ArrayHelper::map(Mobile::find()->asArray()->all(),'id', 'mobile'),

它确实有效,但不显示值。它只有一些空字段。

这是我的视图/索引代码:

<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper ;
use app\models\Mobile;

/* @var $this yii\web\View */
/* @var $searchModel app\models\MobileSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Mobiles';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="mobile-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Mobile', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
                [


                'attribute'=>'id',
                'value'=>'id',
               //'filter'=>array("1"=>"open","2"=>"in progress","3"=>"closed")
                'filter'=>ArrayHelper::map(Mobile::find()->asArray()->all(),'id', 'mobile'),
            ],
            'sim_num',
            'network',
            'twog_network',
            'threeg_network',
            // 'fourg_network',
            // 'technology',
            // 'gps',
            // 'gateway_connection',
            // 'super_id',
            // 'camera',
            // 'resolusion_camera',
            // 'automatic_focus',
            // 'camera_flash',
            // 'video:ntext',
            // 'camera_others:ntext',
            // 'camera_selfie:ntext',
            // 'username',
            // 'body:ntext',
            // 'title:ntext',
            // 'state',
            // 'imageFile',
            // 'size',
            // 'weight',
            // 'inner_memory',
            // 'screen_size',
            // 'screen_type',
            // 'wifi_desc',
            // 'bluetooth',
            // 'batery',
            // 'bady_struct',
            // 'process',
            // 'other:ntext',
            // 'os',
            // 'gesture',
            // 'items',
            // 'speaker',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>

在哪里

<?php

   'attribute'=>'id',
                'value'=>'id',
                'filter'=>ArrayHelper::map(Mobile::find()->asArray()->all(),'id', 'mobile'),
            ],

?>

我重复它显示字段的数量并且在单击每个字段时搜索正确并且它不显示值的小问题...

在网站的检查元素中,我们有:

<option value="2"></option>

我想在选项标签之间显示“2”..

请帮帮我。

【问题讨论】:

  • 是选项,过滤器,应该显示mobile的值而不是id的值.. 2是id的值还是mobile的值??
  • 2 是 id 的值
  • 我不太清楚,但如果你想把 id 值放在选项中,这样映射就足够了:ArrayHelper::map(Mobile::find()->asArray ()->all(),'id', 'id');
  • thaaaank youu..resolved :))) 再次非常感谢 :))))))))))) ;)
  • @areff 我应该将评论发布到答案中以便您关闭问题吗?

标签: php yii yii2 frameworks


【解决方案1】:

来自 cmets,这里是您的问题的解决方案:

ArrayHelper::map(Mobile::find()->asArray()->all(),'id', 'id');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多