Using thinkphp automatic completion to implement an infinite class of classification examples _php examples

Source: Internet
Author: User

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!

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.