/**
  * Creates a new AnItems model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AnItems();
     $NeccFunc = new NeccFunctions();
     // вибираємо головних батьків
     $parentCats = AnCats::find()->roots()->all();
     $list = $NeccFunc->getCorrectList($parentCats);
     // вибираємо регіони
     $regionsQuery = AnRegions::find()->asArray()->all();
     $regions = array();
     // формую правильний масив для select форми
     // хоча потрібно було б використати ArrayHelper::map($array, 'key', 'key')
     foreach ($regionsQuery as $region) {
         $regions[$region['id']] = $region['name'];
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = DATE('Y-m-d H:i:s');
         $model->status = 0;
         $model->local = Yii::$app->language;
         $model->save();
         return $this->redirect('/announcement/anitems');
     } else {
         return $this->render('create', ['model' => $model, 'regions' => $regions, 'list' => $list]);
     }
 }
Exemplo n.º 2
0
 public function init()
 {
     parent::init();
     $NeccFunc = new NeccFunctions();
     $perPage = $this->perPage ? $this->perPage : 10;
     // вибираємо головних батьків
     $parentCats = AnCats::find()->where(['local' => Yii::$app->language])->roots()->all();
     $this->categories = $NeccFunc->getCorrectList($parentCats);
     foreach ($parentCats as $cats) {
         $this->categories[$cats->id] = $cats->name;
     }
     // виборка категорій та регіонів
     //$this->categories = AnCats::find()->addOrderBy('tree')->addOrderBy('lft')->all();
     $parentRegs = AnRegions::find()->roots()->all();
     $this->regions = $NeccFunc->getCorrectList($parentRegs);
     //$this->regions = AnRegions::find()->addOrderBy('tree')->addOrderBy('lft')->all();
     // пошукові запроси, якщо такі є
     $this->searchModel = new AnItemsSearch();
     $this->dataProvider = $this->searchModel->search(Yii::$app->request->queryParams, $perPage);
     $this->registerTranslations();
 }