protected function findModel($id) { if (($model = Comments::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function __construct($id, array $config = []) { parent::__construct($config); if (($model = Comments::findOne($id)) === null) { throw new \yii\web\NotFoundHttpException('The requested page does not exist.'); } foreach ($model->attributes as $key => $value) { $this->{$key} = $value; } if ($model->commentsFields != null) { $commentFields = $model->commentsFields; $commentFields = ArrayHelper::index($commentFields, 'field_name'); } foreach (\Yii::$app->controller->module->fields as $field) { if (isset($commentFields[$field['name']])) { $this->fields[$field['name']] = array_merge($commentFields[$field['name']]->attributes, ['label' => $field['label'], 'fieldType' => isset($field['fieldType']) ? $field['fieldType'] : 'textInput', 'items' => isset($field['items']) ? $field['items'] : null]); } else { $this->fields[$field['name']] = ['comments_id' => $model->id, 'field_name' => $field['name'], 'value' => '', 'label' => $field['label'], 'fieldType' => isset($field['fieldType']) ? $field['fieldType'] : 'textInput', 'items' => isset($field['items']) ? $field['items'] : null]; } } $this->link = $model->commentsLink; }