public function actionIndex() { \Yii::$app->user->setReturnUrl(['site/index']); $eventTypeList = Yii::$app->db->cache(function () { return EventType::find()->indexBy('id')->asArray()->all(); }, Time::SEC_TO_HOUR); return $this->render('index', ['eventTypeList' => $eventTypeList]); }
/** * Страница создания события */ public function actionEdit($id = null) { \Yii::$app->user->setReturnUrl(['event/edit']); $user = \Yii::$app->getUser()->identity; $model = new EventForm(); $model->setScenario(EventForm::SCENARIO_INSERT); if ($id) { $event = Event::findOne(['id' => $id, 'user_id' => $user->getId()]); if (!$event) { throw new NotFoundHttpException(); } $model->setEventModel($event); $model->setScenario(EventForm::SCENARIO_EDIT); } if ($model->load($_POST)) { $model->img = UploadedFile::getInstance($model, 'img'); if ($model->validate() && ($id = $model->save())) { $this->redirect(['event/view', 'id' => $id]); \Yii::$app->end(); } } $eventTypeList = EventType::find()->indexBy('id')->all(); return $this->render('new', ['model' => $model, 'user' => $user, 'eventTypeList' => $eventTypeList]); }
public function getType() { return $this->hasOne(EventType::className(), ['id' => 'event_type_id']); }