This article brings the content is about the thinkphp in the infinite column of the order implementation code, there is a certain reference value, the need for a friend can refer to, I hope you have some help.
In the title we did not indicate whether it is the infinite rank of tp5 or the infinite order of TP3 is to let the small novice understand that these functions are not related to the framework you use, whether you are TP5 or TP3 or Laravel or YII framework is not related, we emphasize the idea, It's the way to solve the problem, because I'm using TP3 so it doesn't matter.
The order of infinite columns is very simple, we have explained many times, this time to blog to share the way we solve the idea.
:
Is the infinite classification we implement, we have to pay attention to two fields, ID and Sorting sort field, the current value of the sort field is 50, is the default value. And then for everyone, the data sheet structure
Sort is used to implement the sequencing PID for Infinite class classification
The key to implementing an infinite class of classification is our writing of the sort field, we take the whole piece of code, but only one line is used:
[Php]<form method= "POST" action= "" ><table class= "table table-bordered table-hover" ><thead class= "" ><tr><th width= "6%" class= "Text-center" >id</th><th width= "6%" class= "Text-center" >pid </th><th width= "8%" class= "Text-center" > Sort </th><th> Column name </th><th width= "16%" class = "Text-center" > Operation </th></tr></thead><tbody><volist name= "CateRes" id= "Cate" >< TR><TD align= "center" >{$cate. ID}</TD><TD align= "center" >{$cate. PID}</TD><TD align= " Center "><input type=" text "Name=" sort[{$cate. ID}] "value=" {$cate. Sort} "/></td><td><?php Echo str_repeat ('-', $cate [' Level ']*8);? >{$cate. CATE_NAME}</TD><TD align= "center" ><a href= "class=" btn btn-primary btn-sm Shiny "><i class= "FA fa-edit" ></i> edit </a><a href= "#" onclick= "Warning (' Do you want to delete ',") "class=" Btn Btn-danger BTN-SM Shiny "><i class=" fa fa-trash-o "></i> Delete </a></td></tr></volist><tr><td colspan= "4" ><button type= "button" tooltip= "Sort" style= "margin-left:225px; width:50px; "class=" btn btn-sm btn-azure Btn-addon "> Sort </button></td></tr></tbody></ Table></form>[/php]
The above code shows that the entire table is wrapped in a form, because we want to submit a sort field, so we need the form.
We implement the core code of infinite Pole column sorting:
[Php]<input type= "text" Name= "sort[{$cate. ID}]" value= "{$cate. Sort}"/>[/php]
That's it, actually we're assembling a sort[] array, the key of each element of the entire array is the ID of the current column and the value is the sorted value of the current column, so that once we commit the array we can modify sort by ID.
Full code:
[Php]public function lst () {$cate =d (' Cate '), if (is_post) {//Sort $data=i (' sort '); foreach ($data as $k = + $v) {$cate Where (array (' id ' = $k))->save ([' sort ' = ' = $v]);} return;} $cateRes = $cate->catetree ();//Infinite Class tree $this->assign ([' cateres ' = $cateRes,]); $this->display (' list ');} [/php]