ThinkPHP3.2 the previous article in the article content page, the next function, and the realization of the classification function

Source: Internet
Author: User

The implementation of the next function of the model layer: note: The ID of the data table should be automatically incremented in case
   Public functionNewsbeforeafter ($url,$id,$cate _id) {//Previous
$where=Array(); $where[' Checks ']=Array(' eq ', 1);//Whether the content of the article is audited$where[' ID ']=Array(' Lt ',$id);//The previous ID should be less than the currently received ID$where[' cate_id ']=Array(' eq ',$cate _id);//Category ID$front=$this->where ($where)->order (' id desc ')->limit (' 1 ')->find ();//the previous article found out if($front){ $burl=$url." /id/".$front[' ID ']. ' /‘.‘ cate_id '. ' /‘.$front[' cate_id '];//Success! Previous post jump address}Else{ $burl= "Javascript:void (0);"; }
Next article
$data =array (); $data[' ID ']=Array(' GT ',$id);//The ID of the next article should be greater than the currently received ID$data[' Checks ']=Array(' eq ', 1); $data[' cate_id ']=Array(' eq ',$cate _id); $after=$this->where ($data)->order (' ID ASC ')->limit (' 1 ')->find ();//next article to find out if($after){ $aurl=$url." /id/".$after[' ID ']. ' /‘.‘ cate_id '. ' /‘.$after[' cate_id '];//Success, next article of the Jump address}Else{ $aurl= "Javascript:void (0);"; } return Array($front,$burl,$after,$aurl); }

View Layer: Example:
<Li><a>Last:</a><ifcondition= "$btitle eq null">It's gone!<Else/><atitle= "<{$btitle [' title ']}>"href= "<{:u ($burl)}>"><{$btitle[' title ']}></a></if></Li><Li><a>Next:</a><ifcondition= "$atitle eq null">It's gone!<Else/><atitle= "<{$atitle [' title ']}>"href= "<{:u ($aurl)}>"><{$atitle[' title ']}></a></if></Li>   

Controller:
//previous Next article            $url= "home/product/product23"; $url=$this->news->newsbeforeafterp ($url,$id,$cate _id); //Previous post Content            $this->assign (' Btitle ',$url[0]); //Previous Address            $this->assign (' Burl ',$url[1]); //Next post Content            $this->assign (' Atitle ',$url[2]); //Next post Address            $this->assign (' Aurl ',$url[3]);
The implementation of classification level two or three function and the method of reducing query database by classification query sub-classification 1. Methods of reducing Query database by classification query sub-classification

Model class:

 Public functionGetgcategorylist ($id=0) {        $arr=$this-Select ();//Query Databaseforeach($arr  as $k=$v) {            if($v[' parent_id '] = =$id) {                $retNext[$k[' cate_id '] =$v[' cate_id ']; $retNext[$k[' cate_name '] =$v[' Cate_name ']; $retNext[$k[' parent_id '] =$v[' parent_id ']; $retNext[$k[' next '] = 0;//used to determine if there are sub-classesforeach($arr  as $VV) {                    if($VV[' parent_id '] = =$v[' cate_id ']) {                        $retNext[$k[' next '] = 1;  Break; }                }                return Array($retNext,$arr); }        }    }

2. Classification of the implementation of the two or three-level function controller:
$list=m (' Category '),Select (); $this->assign (' list ',$list);

View Layer:
<Divclass= "BbD">Superior Category:<Selectname= "parent_id"ID=""style= "margin-left:20px">                            <optionvalue="">--Please choose--</option>                            <foreachname= "List"Item= "V">                                <ifcondition= "$v [' parent_id '] eq 0">//first to get the first level classification                                    <optionvalue= "<{$v [' cate_id ']}>"><{$v[' Cate_name ']}></option>                                    <foreachname= "List"Item= "VV">                                        <ifcondition= "$vv [' parent_id '] eq $v [' cate_id ']">//Two-level classification according to the parent class ID ...                                             <optionvalue= "<{$vv [' cate_id ']}>">|-->|<{$VV[' Cate_name ']}></option>                                            <foreachname= "List"Item= "VVV">                                                <ifcondition= "$vvv [' parent_id '] eq $vv [' cate_id ']">                                                    <optionvalue= "<{$vvv [' cate_id ']}>">|-->|-->|<{$VVV[' Cate_name ']}></option>                                                </if>                                            </foreach>                                        </if>                                    </foreach>                                </if>                            </foreach>                        </Select>                    </Div>

ThinkPHP3.2 the previous article in the article content page, the next function, and the realization of the classification function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.