158
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Действие "view" отображает данные конкретной модели класса "News".
* @param integer $id
* @return mixed
* @throws Возвращает исключение класса "NotFoundHttpException",
если модель не найдена
*/
public function actionView($id)
{
$model = $this->findModel($id);
return $this->render('view', [
'model' => $model,
]);
}
/**
* Действие "create" создает новый экземпляр класса "News" (новую
модель).
* Если операция успешно выполнена, браузер будет перенаправлен на
страницу просмотра (действие 'view').
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->registration_date = date('Y-m-d H:i:s');
$model->id_creator = Yii::$app->user->identity->id;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}