0
在觀看/索引文件,其中示出了模型的所有i的數據使用爲什麼我的過濾器arrayhelper沒有顯示數據庫yii2的值?
'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'),
],
?>
我重複它顯示的字段數量和搜索正確的,當點擊每一個領域和一個小問題它不顯示值...
在檢查網站我們h AVE:
<option value="2"></option>
,我想表演 '2' 選項標籤之間..
請幫助我。
是選項,過濾器,應顯示爲移動而不是ID值的值。2是ID或價值移動的價值? – scaisEdge
2是id的值 – areff
它對我來說並不是很清楚,但是如果你想在選項中加上id值,也許這足以用這種方式進行映射:ArrayHelper :: map(Mobile :: find() - > asArray( ) - > all(),'id','id'); – Masiorama