码迷,mamicode.com
首页 > 微信 > 详细

tp根据数据库动态创建微信菜单

时间:2016-08-25 14:28:42      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:

$button = array();
$class = M(‘ucenter_menu‘)->limit(3)->select();//取出顶级菜单
foreach ($class as $key => $vo) {
    $button[$key] = array(‘name‘=>$vo[‘menu_name‘]);
    $c = M(‘ucenter_menu‘)->where(array(‘pid‘ => $vo[‘id‘]))->limit(5)->select();

    //拼接子菜单
    if ($c != false) {
        foreach ($c as $voo) {
            $button[$key][‘sub_button‘][] = array(
                ‘type‘  => ‘view‘,
                ‘name‘  => $voo[‘menu_name‘],
                ‘url‘   => $voo[‘menu_url‘]
            );
        }
    } else {
        $button[$key][‘type‘] = ‘view‘;
        $button[$key][‘url‘] = $vo[‘menu_url‘];
    }
}

$data = compact(‘button‘);

$menu = new WeChat($options);
$s = $menu->createMenu($data);

if($s){
    $this->success("上线成功");
}else{
    $this->error("上线失败");
}

tp根据数据库动态创建微信菜单

标签:

原文地址:http://www.cnblogs.com/yukewei/p/5806602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!