亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Thinkphp無限級分類代碼

 更新時(shí)間:2015年11月11日 15:37:18   投稿:lijiao  
這篇文章主要介紹了Thinkphp無限級分類代碼,無限級分類真的很重要了,我不會寫怎么辦?本篇就一步步告訴大家如何制作無限級分類,感興趣的小伙伴們可以參考一下

本篇就一點(diǎn)一點(diǎn)教大家寫一個(gè)無限級分類出來,其實(shí)掌握一個(gè)知識,最主要的是要掌握無限級分類的邏輯,那么寫起來就很容易的多了。
首先看數(shù)據(jù)庫表:xp_cate

控制器:CateAction.class.php

<?php
class CateAction extends Action{
function index(){
$cate=M('Cate');
$list=$cate->field("id,name,pid,path,concat(path,'-',id) as bpath")->order('bpath')->select();
foreach($list as $key=>$value){
$list[$key]['count']=count(explode('-',$value['bpath']));
}
$this->assign('alist',$list);
$this->display();
}//添加欄目
function add(){
$cate=new CateModel();if($vo=$cate->create()){
if($cate->add()){
$this->success('添加欄目成功');
}else{
$this->error('添加欄目失敗');
}
}else{
$this->error($cate->getError());
}
}}
?>

模型:CateModel.class.php

<?php
class CateModel extends Model{//對應(yīng)數(shù)據(jù)庫中的表xp_cate
protected $_auto=array(
array('path','tclm',3,'callback'),
);function tclm(){
$pid=isset($_POST['pid'])?(int)$_POST['pid']:0;
echo ($pid);
if($pid==0){
$data=0;
}else{
$list=$this->where("id=$pid")->find();
$data=$list['path'].'-'.$list['id'];//子類的path為父類的path加上父類的id
}
return $data;
}
}
?>

模板:index.html

<form action="/Article/add" method="post">
請選擇父級欄目:<select name="pid" size="20">
<option value="0">根欄目</option>
<volist name="alist" id="vo">
<option value="{$vo['id']}">
<for start="0" end="$vo['count']">
&nbsp;&nbsp;
</for>
{$vo['name']}
</option>
</volist>
</select><br />
新的欄目名稱:<input type="text" name="name" /><br />
<input type="submit" value="添加欄目" />
</form>

顯示結(jié)果如下:

有沒有掌握無限級分類的邏輯,上文分享的thinkphp無限級分類代碼,希望對大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評論