This article shows the method of thinkphp automatic filling to realize infinite level classification, which is one of the common functions of thinkphp, and has practical value. The complete example is now shared with you for your reference. The following steps are implemented:
The table aoli_cate as shown in the following illustration:
One, the action part:
aoli/home/lib/action/cataaction.class.php files are as follows:
<?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 ();
}
Add column
function add () {
$cate =new catemodel ();
if ($vo = $cate->create ()) {
if ($cate->add ()) {
$this->success (' Add column succeeded ');
} else{
$this->error (' Add column failed ');
}
Dump ($VO);
else{
$this->error ($cate->geterror ());}}
? >
Second, the model part:
aoli/home/lib/model/catamodel.class.php files are as follows:
<?php
class Catemodel extends model{//table aoli_cate protected $_auto=array
(
Array (' path ', ' TCLM ') in the corresponding database , 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 '];//Subclass's path is the parent class's path plus the parent class's ID
} return
$data;
}
? >
Third, view views section
The aoli/home/tpl/default/cate/index.html page is as follows:
<form action= "__url__/add" method= "POST" >
Please select parent column: <select name= "pid" size= ">
<option" Value= "0" > Root column </option>
<volist name= "alist" id= "Vo" >
<option value= "{$vo [' id ']}" >
<php> for
($i =0 $i < $vo [' count ']; $i + +) {
echo ';
}
</php>
{$vo [' name ']}
</option>
</volist>
</select><br/>
new column name: <input type= "text" name= "name"/><br/> <input type=
"Submit" value= "add column"/>
</form>
It is believed that the examples mentioned in this paper have some reference value for thinkphp programming.