2017-08-04 1 views
0

dans le fichier de vue/index où toutes les données montrant du modèle i utiliséPourquoi mon filtre arrayhelper n'affiche pas la valeur de la base de données yii2?

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

cela fonctionne vraiment, mais pas afficher les valeurs. et il a juste quelques champs vides.

ici est mon point de vue/code d'index:

<?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'), 
      ], 

?> 

je le répète indique le nombre de champs et recherche corrects quand cliquez sur chaque champs et un petit problème qu'il n'affiche pas les valeurs ...

dans l'élément d'inspection du site nous h ave:

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

et je veux montre '2' entre les balises option ..

S'il vous plaît aidez-moi.

+0

est l'option, le filtre, doit montrer la valeur pour mobile et non la valeur id .. 2 est la valeur d'identité ou valeur de mobile? – scaisEdge

+0

2 est la valeur de l'id – areff

+0

Ce n'est pas vraiment clair pour moi, mais si vous voulez mettre la valeur d'id dans l'option peut-être il suffit de mapper de cette façon: ArrayHelper :: map (Mobile :: find() -> asArray () -> all(), 'id', 'id'); – Masiorama

Répondre

0

A partir des commentaires, voici la solution à votre problème:

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