示例#1
0
 /**
  * 获取国家的栏目列表.
  * 
  * @access public
  * @return void
  */
 public function getListByCountry()
 {
     $intParentId = I('post.pid', NULL);
     // 上级栏目 ID, 默认 NULL, 表示获取国家的全部栏目列表.
     if (NULL !== $intParentId && (int) $intParentId < 1) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     $arrLocateCountry = $this->getLocateCountry();
     // 获取当前请求的定位国家.
     $countryId = (int) $arrLocateCountry['id'];
     // 国家 ID.
     unset($arrLocateCountry);
     $modelCtgClass = new CtgClassModel();
     // 实例化 CtgClass 模型.
     if (NULL === $intParentId) {
         // 获取国家的全部栏目, 要格式化.
         $categoryList = $modelCtgClass->formatList($modelCtgClass->fetchListByCountry($countryId, $intParentId));
     } else {
         // 获取子栏目时, 不用格式化.
         $categoryList = $modelCtgClass->fetchListByCountry($countryId, (int) $intParentId);
     }
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $categoryList)->myAjaxReturn();
 }
 /**
  * 检查发布的栏目是否有效.
  * 
  * @access private
  * @param integer $catId 栏目 ID.
  * @return array 无效时抛异常.
  */
 private function _checkCategory($catId)
 {
     $catId = (int) $catId;
     if ($catId < 1) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     // 数据库检查城市和栏目 ID 是否有效.
     $modelCategory = new CtgClassModel();
     // 栏目模型.
     $categoryInfo = $modelCategory->fetchInfo($catId);
     unset($modelCategory);
     if (empty($categoryInfo)) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     return $categoryInfo;
 }