thinkphp Learning volist Tag Advanced application multiple nesting loops, interlaced color (RPM)

Source: Internet
Author: User


Action Code:

    1. Public Function Index () {
    2. $prod = I ("get.prod_en");
    3. $id = I ("", 0, "int");
    4. if ($prod = = "") {
    5. $serviceProduct = Array (); Array of multi-loop traversal
  1. The data is stored in two tables, where the $serviceproduct array is initialized by looping
  2. $service = M ("Product_class")->order ("oid ASC")->select ();
  3. For ($i = 0; $i < count ($service); $i + +)
  4. {
  5. Array_push ($serviceProduct, Array ("srvname" + =$service [$i] ["PC_CN"], "Product" =>m ("Product")->where ("prod_class_id=").   $service [$i] ["Pcid"])->order ("oid ASC")->select ()));
  6. }
  1. 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
  2. Value, regardless of the type of variable used uniformly assign assignment.
  3. $this->assign ("Serviceproduct", $serviceProduct);
  4. $this->display ();
  5. }else{
  6. if ($id > 0) {
  7. $this->display ("detail");
  8. }else{
  9. $this->assign (' prod_en ', $prod);
  10. $clsList = M ("Question_class")->order ("oid ASC")->select ();
  11. $this->assign (' clslist ', $clsList);
  12. $qusList = M ("question")->order ("oid ASC")->select ();
  13. $this->assign (' quslist ', $qusList);
  14. $this->display ("list");
  15. }
  16. }
  17. }

Template code:

  1. <volist name="serviceproduct" id="sp" key="i">
  2. <DL class="dlist odd">
  3. <DT>{$sp. srvname}</dt>
  4.         <volist < span class= "attribute" >name= "sp.product"  id= "PD"  key= "J" >  
  5. <dd><a href="/index.php/question?prod_en={$pd. prod_en}">{$pd. prod_ CN}</a></dd>
  6. <if condition="$j lt count ($sp [' Product '])">
  7. <DD>| </dd>
  8. </If>
  9. </volist>
  10. <if condition="Count ($sp [' Product ']) EQ 0">
  11. <dd> </dd>
  12. </If>
  13. </dl>
  14. </volist>

When using multiple nested loops, you need to specify a key value for each volist by

    1. <if condition="$j lt count ($sp [' Product '])">

Determines whether the last element in the array.

Volist labels for interlaced discoloration

Method 1:

  1. <volist name="newslist" id="vo" mod="2">
  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>    
  3. </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:

  1. <volist name="newslist" id="vo" key="K">
  2. <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>    
  3. </volist>

The following is a list of examples of TR, TD in a volist loop table:

    1. <tr bgcolor="#FBFCF1">
    2. <volist name="SiteURL" id="Site" mod="4">
    3. <eq name=" mod " value=" 0 " ></tr>< tr bgcolor= "#FBFCF1" ></eq>     
    4. <TD Width="25%"><a href="{$site. URL}" target="_blank">{ $site. Name}</a></td>
    5. </volist>
    6. </tr>

Thinkphp Learn volist tags advanced apps multiple nesting loops, interlaced colors (RPM)

Related Article

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: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: