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 for multi-loop traversal
- // The data is saved in two tables. here, the $ serviceProduct array is initialized cyclically.
- $ Service = M ("product_class")-> order ("oid ASC")-> select ();
- 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 the Template variables
- Value, regardless of the variable type, all use assign value assignment.
- $ 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.
|