2016-12-07 67 views
0

我使用yii2中的活動記錄製作搜索框。當我搜索的東西顯示在表中的結果,但我想訪問表中的記錄的值。 這是我的視圖代碼:如何訪問yii2框架中的活動記錄字段?

<?= GridView::widget([ 
    'dataProvider' => $dataProvider, 
    'columns' => [ 

     'Id', 
     'Property_title', 
     'Price', 
     'Address', 
     'Size', 
     'Construction_year', 
     'Street_distance', 
     'Description', 
     ], 
    ]); 
?> 
+0

需要更多的代碼才能知道這裏發生了什麼。 – Flummox

+0

檢查此$ dataProvider-> getModels(); – jithin

回答

1

首先,你必須找到模型:

$id = 1; // here's your model id 
$model = app\models\Model::findOne($id); // change app\models\Model to your model 

,然後訪問它像普通對象屬性:

$model->id 
$model->Property_title 
0

第一將所有結果存儲到變量並循環顯示如下結果

<? 
$results=$dataProvider->getModels(); 
foreach($results as $result){ 
?> 

<?php echo $result->Id?> 

<?}?>