Example #1
0
 public function getOne($category_id = Null)
 {
     $data = models\Categories::find()->where(['id' => $category_id])->one();
     if ($data === null) {
         return false;
     }
     $catData = $data->attributes;
     $uploadThumbs = $this->uploadThumbs;
     foreach ($uploadThumbs as $thumbType => $sizes) {
         if (empty($catData['image'])) {
             $catData['image_' . $thumbType] = false;
         } else {
             $catData['image_' . $thumbType] = Url::to($this->uploadUrl . '/' . $thumbType . '/' . $catData['image']);
         }
     }
     $countChilds = models\Categories::find()->where(['parent_id' => $data->id])->count();
     if ($countChilds > 0) {
         $catData['sub_categories'] = $this->getAll($parent_id = $data->id);
     }
     $arr[] = $catData;
     return $arr;
 }