예제 #1
0
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #2
0
파일: Category.php 프로젝트: apuc/NDFL
 public function saveNode()
 {
     if ($this->validate()) {
         try {
             if ($this->parent_id == 0) {
                 $this->makeRoot();
             } else {
                 $this->prependTo(Category::findOne(['id' => $this->parent_id]));
             }
         } catch (Exception $e) {
             return false;
         }
         return true;
     }
     return false;
 }
예제 #3
0
파일: Category.php 프로젝트: apuc/NDFL
 public static function getTree($id = 0)
 {
     $exceptionId = [];
     if ($id != 0) {
         $exceptionNode = \backend\modules\category\models\db\Category::findOne(['id' => $id]);
         $exceptionId[] = $id;
         $exceptionNodes = $exceptionNode->children()->all();
         foreach ($exceptionNodes as $node) {
             $exceptionId[] = $node->id;
         }
     }
     $models = Category::find()->orderBy(['tree' => SORT_ASC, 'lft' => SORT_ASC])->where(['not in', 'id', $exceptionId])->all();
     $arr = [0 => 'Корневая'];
     foreach ($models as $model) {
         $arr[$model->id] = str_repeat("    ", $model->lvl) . $model->name;
     }
     return $arr;
 }