ThinkPHP learning (4) multiple nested loops of advanced volist labels

Source: Internet
Author: User
ThinkPHP learning (4) volist tag multiple nested loop Action code for advanced applications: publicfunctionindex () {$ prodI (& quot; get. prod_en & quot;); $ idI (& quot; get. id & quot;, 0, & quot; int & quot;); if ($ prod & quot; & ThinkPHP learning (4) multiple nested loops of advanced volist labels

Action code:

Public function index () {$ prod = I ("get. prod_en "); $ id = I (" get. id ", 0," int "); if ($ prod =" ") {$ serviceProduct = array (); // array traversed by multiple loops
// Data is saved in two tables. here, $ serviceProduct array $ service = M ("product_class")-> order ("oid ASC")-> select () is initialized cyclically (); for ($ I = 0; $ I <count ($ service); $ I ++) {array_push ($ serviceProduct, array ("srvName" => $ service [$ I] ["pc_cn"], "product" => M ("product")-> where ("prod_class_id = ". $ service [$ I] ["pcid"])-> order ("oid ASC")-> select ()));}
// If you want to output variables in the template, you must pass the variables to the template in the controller. The system provides the assign method to assign values to the template variables. all variable types use The assign method to assign values. $ This-> assign ("serviceProduct", $ serviceProduct); $ this-> display ();} else {if ($ id> 0) {$ this-> display ("detail");} else {$ this-> assign ('prod _ EN', $ prod); $ clsList = M ("question_class ") -> order ("oid ASC")-> select (); $ this-> assign ('cllist', $ clsList); $ qusList = M ("question ") -> order ("oid ASC")-> select (); $ this-> assign ('quslist', $ qusList ); $ this-> display ("list ");}}}
Template code:

 
  
 
{$sp.srvName}
{$pd.prod_cn}
|
When multiple nested loops are used, you must specify the key value for each volist.
 
Determines whether it is the last element in the array.


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.