thinkphp Adoption <volist> Implementation of three-level loop code instance _php instance

Source: Internet
Author: User

In this paper, an example is used to describe the implementation of the three-level thinkphp using <volist> tag, and the steps are as follows:

1. A three-level loop requires a three-dimensional array to implement the following code:

function Maketree ($pid, $level) {$map [' pid '] = $pid; 
$map [' level '] = $level; 
$result = $this->where ($map)->order (' Rank ASC ')->findall (); 
 if ($result) {foreach ($result as $key => $value) {$title = $value [' Alias ']; 
 $list [$title] [' id '] = $value [' id ']; 
 $list [$title] [' pid '] = $value [' pid ']; 
 $list [$title] [' Alias ']= $value [' Alias ']; 
 $list [$title] [' title '] = $value [' title ']; 
 $list [$title] [' level '] = $value [' Level ']; 
 $list [$title] [' state '] = $value [' state ']; 
 $list [$title] [' rank '] = $value [' Rank '];
 if ($value [' level ']<=3] {$list [$title] [' child '] = $this->_makesontree ($value [' id ']); 
}} return $list; 
function _makesontree ($pid) {$map [' pid '] = $pid; 
$result = $this->where ($map)->order (' Rank ASC ')->findall (); 
 if ($result) {foreach ($result as $key => $value) {$title = $value [' Alias ']; 
 $list [$title] [' ID ']= $value [' id ']; 
 $list [$title] [' pid ']= $value [' pid ']; 
 $list [$title] [' Alias ']= $value [' Alias ']; $list [$title] [' titl]E '] = $value [' title ']; 
 $list [$title] [' level '] = $value [' Level ']; 
 $list [$title] [' state '] = $value [' state ']; 
  $list [$title] [' rank '] = $value [' Rank ']; 
  if ($this->haschild ($value [' ID '])) {//first determine if there is a third class subclass, the last array is $result[' child ' [' grandchild ']; 
  $list [$title] [' grandchild ']= $this->_makesontree ($value [' id ']); 
 }} return $list; 
The function Haschild ($id) {$result =d (' Learningchannel ')->where ("pid=". $id)->find (); 
 if ($result) {return true; 
else return false;

 }

2. Binding Volist Tags:

 $result =d (' Learning ')->maketree (0,1); 
 Dump ($result);
 $this->assign (' list ', $result);

3. Template section:

<select name= "category" Id= "select" class= "Text Mr5" > 
 <volist name= "list" id= "Vo" > 
  <option Name= "CID" value= "{$vo. ID}" <eq name= "vo.id" value= "GetID" >selected</eq> >{$vo .alias}</option>  
 <volist name= "vo[" "id=" Child "> 
  <option name=" CID "value=" {$child. ID} "<eq name=" Child.id "value=" GetID ">selected</eq> >--{$child .alias}</option> <volist name=  
  " child[" Grandchild '] "id=" grand "> 
  <option name=" CID "value=" {$grand. ID} "<eq name=" grand.id "value=" GetID "> Selected</eq> >---{$grand .alias}</option>  
  </volist> 
 </volist> 
 </ Volist> 
 </select>

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.