前端到後台ThinkPHP開發整站(7)

來源:互聯網
上載者:User

標籤:http   common   cond   public   post   namespace   extend   推薦   ade   

  今晚我繼續這個項目的前台開發,把前台的做出來了,現在項目進行一個收尾工作了,還有欄目頁和一個文章頁的開發,做完這兩個算是完成了。說到這裡感覺有點鬆懈了,把剩下兩個功能頁面做完在吹吧,先看看今天弄的代碼吧!

  前台公用控制器:

<?phpnamespace Home\Controller;use Think\Controller;class CommonController extends Controller{    public function __construct()    {        header(‘Content-type:text/html;charset=utf-8‘);        parent::__construct();    }    /**    *@return 擷取排序資料    */    public function getRank()    {        $conds[‘status‘]=1;        $news=D(‘News‘)->getRank($conds, 10);        return $news;    }    public function error($message = ‘‘)    {        $message=$message?$message:‘系統發生錯誤‘;        $this->assign(‘message‘, $message);        $this->display(‘Index/error‘);    }}

  前台首頁控制器:

<?phpnamespace Home\Controller;use Think\Controller;class IndexController extends CommonController{    public function index($type = ‘‘)    {        //擷取排序資料        $rankNews=$this->getRank();        //擷取首頁大圖資料        $topPicNews=D(‘PositionContent‘)->select(            array(                ‘status‘=>1,                ‘position_id‘=>2            ), 1        );        // 首頁小圖推薦        $topSmailNews=D(‘PositionContent‘)->select(            array(‘status‘=>1,‘position_id‘=>3), 3        );        $listNews=D(‘News‘)->select(array(‘status‘=>1,‘thumb‘=>array(‘neq‘,‘‘)), 30);        $addNews=D(‘PositionContent‘)->select(array(‘status‘=>1,‘position_id‘=>5), 2);        $this->assign(‘result‘, array(            ‘topPicNews‘=>$topPicNews,            ‘topSmailNews‘=>$topSmailNews,            ‘listNews‘=>$listNews,            ‘advNews‘=>$advNews,            ‘rankNews‘=>$rankNews,            ‘catId‘=>0,        ));        /**        *產生靜態頁面        */        if ($type==‘buildHtml‘) {            $this->buildHtml(‘index‘, HTML_PATH, ‘Index/index‘);        } else {            $this->display();        }    }    public function build_html()    {        $this->index(‘buildHtml‘);        return jsonResult(1, ‘首頁緩衝產生成功‘);    }    public function crontab_build_html()    {        if (APP_CRONTAB != 1) {            die(‘the_file_must_exec_crontab‘);        }        $result=D(‘Basic‘)->select();        if (!$result[‘cacheindex‘]) {            die(‘系統沒有設定開啟自動產生首頁緩衝的內容‘);        }        $this->index(‘buildHtml‘);    }    public function getCount()    {        if (!$_POST) {            return jsonResult(0, ‘沒有任何內容‘);        }        $newsIds=array_unique($_POST);        try {            $list=D(‘News‘)->getNewsByNewsIdIn($newsIds);        } catch (Exception $e) {            return jsonResult(0, $e->getMessage());        }        if (!$list) {            return jsonResult(0, ‘notdata‘);        }        $data=array();        foreach ($list as $k => $v) {            $data[$v[‘news_id‘]]=$v[‘count‘];        }        return jsonResult(1, ‘success‘, $data);    }}

  今天就寫了這兩個類,其實已經不難了,都是那麼兩板斧了。今天就到這睡覺了!

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

前端到後台ThinkPHP開發整站(7)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.