Thinkphp volist label nested loop tutorial, thinkphpvolist_PHP tutorial

Source: Internet
Author: User
Thinkphp volist label nested loop tutorial, thinkphpvolist. Thinkphp volist label nested loop tutorial, thinkphpvolist this article describes the usage of ThinkPHP volist label nesting in details as follows: first, in the Thinkphp Development Manual, tutorial on nested loop of volist labels with Thinkphp, thinkphpvolist

The usage of volist tag nesting in ThinkPHP is described as follows:

First, in the Thinkphp Development Manual Description of label nesting. As follows:

Label nesting:

The template engine supports the multi-layer nesting function of tags. you can specify the tags of the tag library to be nested.
In the built-in labels, volist (and its alias iterate), switch, if, elseif, else, foreach, compare (including all comparison labels), (not) present, (not) empty, (not) defined, and other labels can be nested. For example:

 
  
   {$sub.name}
  
 

The preceding labels can be used to output dual loops.

The default nesting level is 3, so the nesting level cannot exceed 3. if you need more layers, you can specify the TAG_NESTED_LEVEL configuration parameter.
But how should I assign a value to "list" in the Action? From the description, we can see that list should be a two-dimensional array. Below is a piece of test code, which can be used after testing.

$Baojia=new Model('baojia');$Class=new Model('class');$parent=$Class->select();   foreach($parent as $n=> $val){$parent[$n]['voo']=$Baojia->where('belongto=\''.$val['name'].'\'')->select();}$this->assign('list',$parent);
 
      {$vo.name}
  
{$sub.name}

Two tables are defined in the database. one is a classification table and the other is a classification table. the function is to display a category like a tree menu. Each category is quoted for each model.

The main functions of the code are:

1. create a model first:

$Baojia=new Model('baojia');$Class=new Model('class');

2. this step is very important to query the data in the category, because we know that the database query returns two-dimensional data similar to the table. when we retrieve a single piece of data, it is equivalent to reading each row of data. When The thinkphp background will automatically read each row of data.

$parent=$Class->select(); 

Store the quoted data to $ parent, where $ n is the serial number of the $ parent array, which is equivalent to storing the data table in $ parent. an index is added to each row, this index points to the quotation for this category.

foreach($parent as $n=> $val){$parent[$n]['voo']=$Baojia->where('belongto=\''.$val['name'].'\'')->select();   }

3. finally:

$this->assign('list',$parent);

Show output!

Through this program, you can have a deeper understanding Tag, in fact, if you are operating in the database, The label name can only be assign to the database table type (of course, it can also be array type, because the data queried by the database itself is array type). when we call When calling tags, especially nested calls, always remember that the names of each layer must be array-type, such as the outermost layer in the program, The list here is the $ parent we initially defined. this variable points to the data table obtained by querying the class table. That is, the data table pointed to by $ parent [$ n] ['voo'], that is, the corresponding data in the orders table.

Through this analysis, the organization is clear, and N re-loops can be achieved through the first step. of course, if you need more layers, you can specify the TAG_NESTED_LEVEL configuration parameter.

In this way, multiple cycles such as country> province> City> County> township can be achieved.


In thinkphp, I made a three-layer nesting of volist. there is a form in the three-layer, and an error occurs when I put the input tag in the form on the third layer.

Can I change it to $ c ['child?

Nested volist in ThinkPHP

$ This-> assign ('list1', $ array );

The usage of volist tag nesting in ThinkPHP is described in detail in this article: first, in the Thinkphp development manual, there are...

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.