40 min. thinkphp Loop nesting prints out a list of parent and child classes, how to handle

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}




  • 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.