/**
  * Finds the Category model based on its path.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $path
  * @throws \yii\web\NotFoundHttpException
  * @return Category the loaded model
  */
 protected function findModel($path)
 {
     if (($model = Category::findByPath($path)->active()->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return array_merge(parent::behaviors(), ['sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name', 'ensureUnique' => true], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => false], 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedImage' => ['filesystem' => 'local', 'path' => '/categories', 'fileName' => '{model.slug}.{file.extension}', 'relation' => 'image', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) {
         $image = ImageManagerStatic::make($file->getPath());
         $image->resize(300, null, function (Constraint $constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         $image->save($file->getPath(), 100);
     }]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['image' => ['deleteOnUnlink' => true]], 'relations' => ['imageRelation' => $this->hasOne(ProductCategoryFile::className(), ['id' => 'image_id'])]]]);
 }
Esempio n. 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'root' => $this->root, 'lft' => $this->lft, 'rgt' => $this->rgt, 'lvl' => $this->lvl, 'icon_type' => $this->icon_type, 'active' => $this->active, 'selected' => $this->selected, 'disabled' => $this->disabled, 'readonly' => $this->readonly, 'visible' => $this->visible, 'collapsed' => $this->collapsed, 'movable_u' => $this->movable_u, 'movable_d' => $this->movable_d, 'movable_l' => $this->movable_l, 'movable_r' => $this->movable_r, 'removable' => $this->removable, 'removable_all' => $this->removable_all]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'icon', $this->icon]);
     return $dataProvider;
 }
 /**
  * @inheritdoc
  */
 protected function getModelClass()
 {
     return Category::className();
 }