ThinkPHP auto-Fill Method for unlimited classification, thinkphp Filling

Source: Internet
Author: User

ThinkPHP auto-Fill Method for unlimited classification, thinkphp Filling

This example shows how ThinkPHP automatically fills in to implement unlimited classification. It is one of the common functions of ThinkPHP and is very useful. We will share the complete instance for your reference. The specific implementation steps are as follows:

Shows the table aoli_cate:

I. action:

The aoli/Home/Lib/Action/CataAction. class. php file is as follows:

<? Phpclass 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 function add () {$ cate = new CateModel (); if ($ vo = $ cate-> create () {if ($ cate-> add () {$ thi S-> success ('column added successfully');} else {$ this-> error ('column addition failed');} // dump ($ vo );} else {$ this-> error ($ cate-> getError () ;}}}?>

Ii. Model:

The aoli/Home/Lib/Model/CataModel. class. php file is as follows:

<? Phpclass CateModel extends Model {// corresponding to the database table aoli_cate protected $ _ auto = 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']; // the path of the subclass is the path of the parent class plus the id of the parent class.} return $ data ;}}?>

Iii. view part

The aoli/Home/Tpl/default/Cate/index.html page is as follows:

<Form action = "_ URL _/add" method = "post"> select parent columns: <select name = "pid" size = "20"> <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 Topic name: <input type = "text" name = "name"/> <br/> <input type = "submit" value = "add topic"/> </form>

I believe the examples described in this article have some reference value for ThinkPHP program design.


Automatic thinkphp Filling

Silly bird, The Last Logon Time and the last logon ip address need to be manually written to update the method. Call the update method you wrote when verifying that the login is successful.
The filling set in the Model is automatically filled when operating data.

You have misunderstood the concept.
 
Php + mysql three-level classification, Li Wenkai thinkphp unlimited Classification

So, what do you want to ask? Well, I have watched this video,
 

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.