Exemple #1
0
 public function getCategories(&$data = [], $parent = NULL)
 {
     $category = Category::find()->where(['parent_id' => $parent, 'type' => 'news'])->andWhere(['NOT IN', 'id', !$this->isNewRecord ? $this->id : 0])->all();
     foreach ($category as $key => $value) {
         $data[$value->id] = $this->getIndent($value->indent) . $value->title;
         unset($category[$key]);
         $this->getCategories($data, $value->id);
     }
     return $data;
 }
Exemple #2
0
 public function getCategory()
 {
     $post = Post::findOne($this->id);
     foreach (explode(',', $post->category_id) as $value) {
         $category = Category::findOne($value);
         if (!empty($category)) {
             $data[] = ['id' => $category->id, 'parent_id' => $category->parent_id, 'title' => $category->title, 'indent' => $this->getIndent($category->indent)];
         }
     }
     return $data;
 }