zoukankan      html  css  js  c++  java
  • 前端到后台ThinkPHP开发整站(完)

      久违了,今天终于抽空把最后的写完了,这是这个项目的最后一篇文章了,把前台的栏目控制器和文章内容控制器的功能实现了。

      栏目控制器:

    <?php
    namespace HomeController;
    use ThinkController;
    class CatController extends CommonController{
        public function index(){
            $id=intval($_GET['id']);
            if(!$id){
                return $this->error('ID不存在');
            }
    
            $nav=D('Menu')->find($id);
            if(!$nav || $nav['status']!=1){
                return $this->error('栏目id不存在或者状态不为正常');
            }
            $advNews=D('PositionContent')->select(array('status'=>1,'position_id'=>5),2);
            $rankNews=$this->getRank();
    
            $page=$_REQUEST['p']?$_REQUEST['p']:1;
            $pageSize=20;
            $conds=array(
                'status'=>1,
                'thumb'=>array('neq',''),
                'catid'=>$id
            );
            $news=D('News')->getNews($conds,$page,$pageSize);
            $count=D('News')->getNewsCount($conds);
    
            $res=new ThinkPage($count,$pageSize);
            $pageres=$res->show();
    
            $this->assign('result',array(
                'advNews'=>$advNews,
                'rankNews'=>$rankNews,
                'catId'=>$id,
                'listNews'=>$news,
                'pageres'=>$pageres
            ));
            $this->display();
        }
    }
    ?>
    

      文章内容控制器:

    <?php
    namespace HomeController;
    use ThinkController;
    class DetailController extends CommonController{
        public function index(){
            $id=intval($_GET['id']);
            if(!$id || $id<0){
                return $this->error('ID不合法');
            }
    
            $news=D('News')->find($id);
    
            if(!$news || $news['status']!=1){
                return $this->error('ID不存在或者资讯被关闭');
            }
    
            $count=intval($news['count'])+1;
            D('News')->updateCount($id,$count);
    
            $content=D('NewsContent')->find($id);
            $news['content']=htmlspecialchars_decode($content['content']);
            $advNews=D('PositionContent')->select(array('status'=>1,'position_id'=>5),2);
            $rankNews=$this->getRank();
            $this->assign('result',array(
                'rankNews'=>$rankNews,
                'advNews'=>$advNews,
                'catId'=>$news['catid'],
                'news'=>$news
            ));
            $this->display('Detail/index');
        }
    
        public function view(){
            if(!getLoginUsername()){
                $this->error('您没有权限访问该页面');
            }
            $this->index();
        }
    }
    ?>
    

      终于坚持的把该项目做完了,这个项目我也是上淘宝买的教程,边学边做的!可能还会有很多BUG和可改善的地方,日后慢慢检查作修改。

    源码地址:https://github.com/YoZiLin/TP-CMS

  • 相关阅读:
    < java.util >-- Set接口
    Codeforces 627 A. XOR Equation (数学)
    Codeforces 161 B. Discounts (贪心)
    Codeforces 161 D. Distance in Tree (树dp)
    HDU 5534 Partial Tree (完全背包变形)
    HDU 5927 Auxiliary Set (dfs)
    Codeforces 27E. Number With The Given Amount Of Divisors (暴力)
    lght oj 1257
    Codeforces 219D. Choosing Capital for Treeland (树dp)
    Codeforces 479E. Riding in a Lift (dp + 前缀和优化)
  • 原文地址:https://www.cnblogs.com/lzy138/p/7374296.html
Copyright © 2011-2022 走看看