public function getCategory($redirect = false) { $category_id = Yii::$app->request->get('category'); $category = Categories::findOne($category_id); if ($category === null && $redirect) { Yii::$app->getSession()->setFlash('warning', Yii::t('backend', 'Категория не существует')); return $this->redirect(['categories']); } elseif ($category === null) { return new Categories(); } return $category; }
public function getUrl() { if ($this->type == 4) { return \yii\helpers\Json::decode($this->url); } elseif ($this->type == 5) { return $this->url; } elseif ($this->type == 1) { if (($application = Applications::findOne($this->application_id)) !== null) { return $application->url; } } elseif ($this->type == 2) { if (($category = Categories::findOne($this->category_id)) !== null) { return $category->url; } } elseif ($this->type == 3) { $item = Items::find()->where([Items::tablename() . '.id' => $this->item_id])->one(); if ($item !== null) { return $item->url; } } return '#'; }