/** * Finds the Sensor model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Sensor the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Sensor::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use common\models\Sensor; use yii\helpers\Html; use yii\grid\GridView; $this->title = 'Danh sách thông báo'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="message-index"> <h4><?php echo Html::encode($this->title); ?> </h4> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['width' => '6%']], ['attribute' => 'sensor_id', 'value' => function ($model) { $sensor = Sensor::findOne($model->sensor_id); return $sensor['name']; }], 'message_0', 'message_1', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'options' => ['width' => '10%']]]]); ?> </div>