예제 #1
0
 public function showlist()
 {
     //取出商品栏目
     $cat_model = new \Model\CategoryModel();
     $cat_list = $cat_model->getTree();
     $this->assign('cat_list', $cat_list);
     //取出商品并分页显示
     $goods_model = new \Model\GoodsModel();
     $pagesize = C('pagesize');
     $count = $goods_model->count();
     $page = new \Think\Page($count, $pagesize);
     //设置分页样式
     $page->lastSuffix = false;
     //不显示末页
     $page->rollPage = 3;
     //一次显示三页
     $page->setConfig('prev', '【上一页】');
     $page->setConfig('next', '【下一页】');
     $page->setConfig('first', '【首页】');
     $page->setConfig('last', '【末页】');
     $page->setConfig('theme', '共 %TOTAL_ROW% 条记录,当前 %NOW_PAGE%/%TOTAL_PAGE%%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
     $pageinfo = $page->show();
     //获取当前页方便跳转
     $nowpage = $page->nowPage;
     $goods_list = $goods_model->order('goods_id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
     $this->assign('goods_list', $goods_list);
     $this->assign('pageinfo', $pageinfo);
     $this->assign('nowpage', $nowpage);
     $this->display();
 }
예제 #2
0
 public function index()
 {
     //取出层级格式化过的栏目信息,用于前台左侧菜单栏显示
     //每次都递归取出,服务器和数据库压力都很大,优化方法将数据缓存存入memcache中
     S(array('type' => 'memcache', 'host' => 'localhost', 'port' => '11211'));
     //直接从缓存中取cat_list
     $cat_list = S('catl_ist');
     //如果为空,则去服务器将数据取出并加入到memcache缓存中
     if (empty($cat_list)) {
         $cat_model = new \Model\CategoryModel();
         $cat_list = $cat_model->getTree();
         S('cat_list', $cat_list, 3600 * 24);
     }
     $this->assign('cat_list', $cat_list);
     //在首页取出精品热卖新品商品
     $goods_model = new \Model\GoodsModel();
     // 这种写法不用assign直接属性赋值
     $this->goods_hot_list = $goods_model->getGoodsByType('hot', 3);
     $this->goods_new_list = $goods_model->getGoodsByType('new', 3);
     $this->goods_best_list = $goods_model->getGoodsByType('best', 3);
     $this->display();
 }
 public function update($cat_id)
 {
     $cat_id = (int) $cat_id;
     $model = new \Model\CategoryModel();
     if (IS_POST) {
         if ($data = $model->create(I('post.'), 2)) {
             //查找自身和下级的cat_id,防止修改表单恶意提交(将自身或者下级作为自身的父级)
             $ids = $model->getChild($cat_id);
             $ids[] = $cat_id;
             $parent_id = (int) I('post.parent_id');
             if (in_array($parent_id, $ids)) {
                 $this->error('不能讲自身和下级栏目作为自身的父级');
             }
             if ($model->save($data) !== false) {
                 $this->success('修改成功', U('showlist'), 1);
                 exit;
             } else {
                 $this->error('修改失败');
             }
         } else {
             $this->error($model->getError());
         }
     }
     //取出要修改栏目的信息
     $info = $model->find($cat_id);
     $this->assign('info', $info);
     //取出要修改的栏目的自身和下级栏目,在修改界面不显示
     $ids = $model->getChild($cat_id);
     $ids[] = $cat_id;
     $this->assign('ids', $ids);
     //取出商品栏目
     $cat_list = $model->getTree();
     $this->assign('cat_list', $cat_list);
     $this->display();
 }