40 min. thinkphp Loop nesting prints out a list of parent and child classes, how to resolve
Source: Internet
Author: User
40 min. thinkphp Loop nesting prints out a list of parent and child classes
Hello everybody, I am learning thinkphp frame In recent time, I want to make a data list in the template page, the format is: first the parent category name, then print out the corresponding subclass list, then print another parent class name, then print the corresponding subclass of the parent class, and so on ... I am using form layout, format such as:
Introduction to Category names
Parent class Name 1......
Subclass Name 1 .....
Subclass Name 2 .....
Subclass Name 3 .....
Parent class Name 2......
Subclass Name 1 .....
Subclass Name 2 .....
Subclass Name 3 .....
Ask how to achieve with volist, or there is no better way, please advise, grateful!!
------Solution--------------------
Don't you read his handbook?
Volist Label
Volist tags are used primarily for looping output datasets or multidimensional arrays in a template.
The result of the typical model's select and FindAll methods is a two-dimensional array that can be output directly using the volist tag.
In action, first assign a value to the stencil:
$User = M (' User ');
$list = $User->select ();
$this->assign (' list ', $list);
In the template definition as follows, loop out the user's number and name:
{$vo. ID}
{$vo. Name}
The Name property of the volist tag represents the variable names assigned to the template, so it is not optional to change in the template file. The ID represents the current loop variable and can be arbitrarily specified, but make sure that you do not conflict with the Name property, for example:
{$data. ID}
{$data. Name}
Support output part of data, such as the output of the 5th to 15th record
{$vo. Name}
Output even record
{$vo. Name}
MoD properties are also used to control the line breaks for a certain record, for example:
{$vo. Name}
Output loop variable
{$k}. {$vo. Name}
If the key attribute is not specified, the loop variable i is used by default, for example:
{$i}. {$vo. Name}
If you want to output the index of an array, you can directly use the key variable, and the loop variable is that the key is determined by the data itself, not the loop control, for example:
{$key}. {$vo. Name}
Volist also has an alias iterate, usage and volist are the same.
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.