Esempio n. 1
0
/**
 * 获取地区父级路径路径
 * @param $parentid 父级ID
 * @param $keyid 菜单keyid
 * @param $callback json生成callback变量
 * @param $result 递归返回结果数组
 * @param $infos
 */
function ajax_getpath($parentid, $keyid, $callback, $result = array(), $infos = array())
{
    $keyid = intval($keyid);
    $parentid = intval($parentid);
    if (!$infos) {
        $datas = getcache($keyid, 'linkage');
        $infos = $datas['data'];
    }
    if (array_key_exists($parentid, $infos)) {
        $result[] = iconv(CHARSET, 'utf-8', $infos[$parentid]['name']);
        return ajax_getpath($infos[$parentid]['parentid'], $keyid, $callback, $result, $infos);
    } else {
        if (count($result) > 0) {
            krsort($result);
            $jsonstr = json_encode($result);
            echo trim_script($callback) . '(', $jsonstr, ')';
            exit;
        } else {
            $result[] = iconv(CHARSET, 'utf-8', $datas['title']);
            $jsonstr = json_encode($result);
            echo trim_script($callback) . '(', $jsonstr, ')';
            exit;
        }
    }
}
Esempio n. 2
0
/**
 * 获取地区父级路径路径
 * @param $parentid 父级ID
 * @param $keyid 菜单keyid
 * @param $callback json生成callback变量
 * @param $result 递归返回结果数组
 * @param $infos
 */
function ajax_getpath($parentid, $keyid, $callback, $path = 'commons', $result = array(), $infos = array())
{
    $path = str_replace(array('/', '//'), '', $path);
    $keyid = str_replace(array('/', '//'), '', $keyid);
    $parentid = intval($parentid);
    if (!$infos) {
        $infos = getcache($keyid, $path);
    }
    if (array_key_exists($parentid, $infos)) {
        $result[] = iconv(CHARSET, 'utf-8', trim($infos[$parentid]['catname']));
        return ajax_getpath($infos[$parentid]['parentid'], $keyid, $callback, $path, $result, $infos);
    } else {
        if (count($result) > 0) {
            krsort($result);
            $jsonstr = json_encode($result);
            echo trim_script($callback) . '(', $jsonstr, ')';
            exit;
        } else {
            $result[] = iconv(CHARSET, 'utf-8', $datas['title']);
            $jsonstr = json_encode($result);
            echo trim_script($callback) . '(', $jsonstr, ')';
            exit;
        }
    }
}