First, the realization effect
Second, the main code
1, template
2. Controller
Index Module
Add Module
3. Model
Third, the Code
So you can reader copy the test.
1, template
<form action= "__url__/add" method= "POST" >
column <select name= "FID" size=20> <option
"0" > Columns </option>
<volist name= ' list ' id= ' vo ' >
<option value= ' {$vo [' id ']} ' >
{$vo [' Blank ']}{$vo [' name ']}</option>
</volist>
</select><br/>
Add column: <input type = "text" name= ' name '/><br/>
<input type= "Submit" value= "Add"/>
</form>
2. Controller
<?php
class Indexaction extends Action
{
/**
+------------------------------------------------ ----------
* Default action
+----------------------------------------------------------/public
function Index () {
$Column =new columnmodel ();
$list = $Column->field ("Id,name,fid,sort,concat (Sort, '-', id) nsort")->order (' nsort asc ')->select ();
foreach ($list as $key => $val) {
$layer =count ('-', $list [$key] [' nsort ']);
$list [$key] [' Blank ']= '];
For ($i =0 $i < $layer; $i + +) {
if ($i = = $layer-1) {
$list [$key] [' Blank '].= '---| ';
} else{
$list [$key] [' Blank '].= '---'
;
}
}} $this->assign (' list ', $list);
$this->display ();
}
Public function Add () {
$Column =new Columnmodel;
$Column->create ();
if ($Column->add ()) {
$this->success (' Add success ');
} else{
$this->error ($Column->geterror ());}}
? >
3. Model
<?php
class Columnmodel extends model{
protected $_auto=array (
array (' name ', ' trim ', 0, ' function '),// Filter the blank character
array (' sort ', ' createsort ', 0, ' callback ') that the user accidentally enters
;
*
* Auto-complete sort field
* Query the superior sort based on the FID from the post to determine that this level of sort
*
/protected function Createsort () {
$fid =$ _post[' FID ']? (int) $_post[' FID ']:0;//if the user does not select a parent column, the default parent column ID is 0
if ($fid!= ' 0 ') {
$list = $this->where ("id= $fid")-> Find ();
$data = $list [' sort ']. -'. $fid;
} else{
$data = ' 0 ';
}
return $data;
}
? >
The above is a small set of thinkphp to introduce the automatic completion of the implementation of an unlimited number of classification examples, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!