Action Code:
[PHP]
- Public Function Index () {
- $prod = I ("get.prod_en");
- $id = I ("Get.id", 0, "int");
- if ($prod = = "") {
- $serviceProduct = Array (); Array of multi-loop traversal
[PHP]
- The data is stored in two tables, where the $serviceproduct array is initialized by looping
- $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 ()));
- }
[PHP]
- If you want to output a variable in a template, you must pass the variable to the template in the controller, and the system provides the Assign method to assign the template variable
- Value, regardless of the type of variable used uniformly assign 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 (' clslist ', $clsList);
- $qusList = M ("question")->order ("oid ASC")->select ();
- $this->assign (' quslist ', $qusList);
- $this->display ("list");
- }
- }
- }
Template code:
[HTML]
- <volist name="serviceproduct" id="sp" key="i">
- <DL class="dlist odd">
- <DT>{$sp. srvname}</dt>
- <volist < span class= "attribute" >name= "sp.product" id= "PD" key= "J" >
- <dd><a href="/index.php/question?prod_en={$pd. prod_en}">{$pd. prod_ CN}</a></dd>
- <if condition="$j lt count ($sp [' Product '])">
- <DD>| </dd>
- </If>
- </volist>
- <if condition="Count ($sp [' Product ']) EQ 0">
- <dd> </dd>
- </If>
- </dl>
- </volist>
When using multiple nested loops, you need to specify a key value for each volist by
[HTML]
- <if condition="$j lt count ($sp [' Product '])">
Determines whether the last element in the array.
Volist labels for interlaced discoloration
Method 1:
[HTML]
- <volist name="newslist" id="vo" mod="2">
- <Li<eqName="MoD"Value="0">style="Background-color: #000;"</eq>><Span> <a href= >{$vo. Title}</ a></span ><span>{$vo. edittime|< span class= "attribute" >date= "y year M month D Day", ###}</ span><span >{$vo. Author}</span>< span class= "tag" ></li>
- </volist>
The MoD parameter in Volist is equivalent to specifying a frequency, and the system will calculate the current actual record for the MoD parameter value (% operator in PHP). In conjunction with a judgment label (such as an EQ tag), the output data or data display format can be controlled according to the frequency.
Method 2:
[HTML]
- <volist name="newslist" id="vo" key="K">
- <Li<Ifcondition="$k%2== ' 0 '">style="Background-color: #000;"</If>><Span><a href= >{$vo. Title}</ a></span ><span> {$ vo.edittime| date= "y year M month D Day", ###}</ span><span >{$vo. Author}</span>< span class= "tag" ></li>
- </volist>
The following is a list of examples of TR, TD in a volist loop table:
[HTML]
- <tr bgcolor="#FBFCF1">
- <volist name="SiteURL" id="Site" mod="4">
- <eq name=" mod " value=" 0 " ></tr>< tr bgcolor= "#FBFCF1" ></eq>
- <TD Width="25%"><a href="{$site. URL}" target="_blank">{ $site. Name}</a></td>
- </volist>
- </tr>
Thinkphp Learn volist tags advanced apps multiple nesting loops, interlaced colors (RPM)