/** * Finds the Department model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Department the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Department::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use app\components\helpers\Phone; use app\models\Post; use app\modules\department\models\Department; use app\modules\user\models\User; use yii\helpers\Html; use yii\widgets\DetailView; echo DetailView::widget(['model' => $model, 'attributes' => [['attribute' => 'post_id', 'value' => $model->post_id ? Post::findOne($model->post_id)->title : ''], ['attribute' => 'department_id', 'format' => 'raw', 'value' => $model->department_id ? Html::a(Department::findOne($model->department_id)->title, ['/department/view', 'id' => $model->department_id]) : ''], ['attribute' => 'user_id', 'format' => 'raw', 'value' => $model->user_id ? Html::a(User::findOne($model->user_id)->getName(), ['/user/view', 'id' => $model->user_id]) : ''], ['attribute' => 'phone_stationary', 'format' => 'raw', 'value' => Html::a(Phone::getFormatView($model->phone_work), 'tel:' . $model->phone_work)], ['attribute' => 'phone_work', 'format' => 'raw', 'value' => Html::a(Phone::getFormatView($model->phone_work), 'tel:' . $model->phone_work)], 'email_work:email', 'cabinet', 'worked_at:date', ['attribute' => 'experience', 'format' => 'raw', 'value' => $model->getExperience()], 'rate', ['attribute' => 'status', 'format' => 'raw', 'value' => 1]]]);