cmf获取指定分类的父级分类id

在使用cmf开发模板过程中,有时候需要获取指定分类的父级分类,可以用以下函数_wien_parentCategoriesId()

php代码:

/**
 * 获取指定分类的父级分类id
 */
if (!function_exists('_wien_parentCategoriesId')) {
    function _wien_parentCategoriesId($categoryId)
    {

        $portalCategoryModel = new PortalCategoryModel();

        $path = $portalCategoryModel->where(['id' => $categoryId])->value('path');

        //根据"-"分割成数组
        $var=explode("-",$path);
        //取倒数第二个数字
        $parentId=$var[count($var)-2];

        return $parentId;
    }
}


Comments 0

0.154187s