ARCates::getCateName PHP Method

getCateName() public static method

根据分类id获取分类名
public static getCateName ( type $id, type $level = null ) : type
$id type
$level type
return type
    public static function getCateName($id, $level = null)
    {
        $query = new Query(Yii::app()->db);
        $query->select('name');
        $query->from('groupon_cates');
        $query->andWhere('id=:id', array(':id' => $id));
        if ($level) {
            $query->andWhere('level=:level', array(':level' => $level));
        }
        $name = $query->queryScalar();
        return $name;
    }

Usage Example

Example #1
0
 public static function cateInfo($data)
 {
     $str = '';
     $str .= '一级分类:' . ARCates::getCateName($data['cate_1_id'], ARCates::LEVEL_ONE) . '<br />';
     $str .= '二级分类:' . ARCates::getCateName($data['cate_2_id'], ARCates::LEVEL_TWO) . '<br />';
     if ($data['cate_3_id'] > 0) {
         $str .= '三级分类:' . ARCates::getCateName($data['cate_3_id'], ARCates::LEVEL_THREE);
     }
     return $str;
 }