Loop array does not loop out the required data in the thinkphp template

Source: Internet
Author: User
I wrote the array in the project configuration file config.php, the code
/* Website left column navigation */' menu ' = + Array (   ' headnav ' + ' Control Panel ', ' subnav ' = ' = ' Array (   ' name ' = ' System settings ', ' Menumark ' + ' System ', ' url ' = ' system/index '), Array (' name ' = ' = ' navigation management ', ' menumark ' = ' nav ', ' url ' = ' + ' nav/ Navlist '), Array (' name ' = ' advertising image ', ' menumark ' = ' Show ', ' url ' = = ' show/showlist '), Array (' name ' = = ' Manage list ', ' Me Numark ' = ' Admin ', ' url ' = ' admin/adminlist '),),   

The code inside the template is like this, as follows:
 
 
  
  
   

{$v. Headnav}

  • {$v 2.name}

Depressed death personally, I have written before another framework, can be used, but transplanted to thinkphp will not be.


Reply to discussion (solution)

foreach inside the value of the menu you are how to come ...

Config.php inside the array to be used, you need to use the C () method to obtain, you in the controller first $this->assign (' Menu ', C (' menu '));

Config.php inside the array to be used, you need to use the C () method to obtain, you in the controller first $this->assign (' Menu ', C (' menu '));


I've assigned a value in the public controller, and I can print it out.

You made a mistake with the loop object, the modified part of the code is referenced below:

{$menu ["Headnav"]}

  • {$v 2.name}

You made a mistake with the loop object, the modified part of the code is referenced below:

{$menu ["Headnav"]}

  • {$v 2.name}


This doesn't seem to be the right thing to do with the next level array.

Replace the Volist label with a foreach label.

                    
 
                          
  
   
  • {$v 2.name}
  • Replace the Volist label with a foreach label.

                        
     
                              
      
       
  • {$v 2.name}

  • This is not the same as the loop label, landlord original writing is not wrong, is related to the definition of the array, according to this can only loop out a set of arrays.

    The correct definition of an array in config.php should look like this:

    /* On the left side of the site navigation */' menu ' = + Array ('  menu[1] ' = = Array (      ' headnav ' + ' Control Panel ',      ' subnav ' = + Array (         Array (' name ' = ' = ' Site Settings ', ' menumark ' = ' System ', ' url ' = ' system/index '),         Array (' name ' = ' = ' navigation management ', ' Menuma RK ' + ' Nav ', ' url ' = ' + ' nav/navlist '),         Array (' name ' = ' + ' ad management ', ' menumark ' = ' Show ', ' url ' = = ' Show/sho Wlist '),         Array (' name ' = = ' management list ', ' Menumark ' + ' admin ', ' url ' = = ' admin/adminlist '),),       ' menu[2] ' => ; Array (      ' headnav ' + ' single page management ',      ' subnav ' = = Array (         ' name ' = ' + ' single page Management ', ' menumark ' = ' ' page ', ' url ' = ' page/pagelist '),),      

    Change the configuration array so that the template's loop label is correct.

    The correct definition of an array in config.php should look like this:

    /* On the left side of the site navigation */' menu ' = + Array ('  menu[1] ' = = Array (      ' headnav ' + ' Control Panel ',      ' subnav ' = + Array (         Array (' name ' = ' = ' Site Settings ', ' menumark ' = ' System ', ' url ' = ' system/index '),         Array (' name ' = ' = ' navigation management ', ' Menuma RK ' + ' Nav ', ' url ' = ' + ' nav/navlist '),         Array (' name ' = ' + ' ad management ', ' menumark ' = ' Show ', ' url ' = = ' Show/sho Wlist '),         Array (' name ' = = ' management list ', ' Menumark ' + ' admin ', ' url ' = = ' admin/adminlist '),),       ' menu[2] ' => ; Array (      ' headnav ' + ' single page management ',      ' subnav ' = = Array (         ' name ' = ' + ' single page Management ', ' menumark ' = ' ' page ', ' url ' = ' page/pagelist '),),      

    Change the configuration array so that the template's loop label is correct.

    。。。。。。

    Misakaqunianx ... What's the problem with this?

    The correct definition of an array in config.php should look like this:

    /* On the left side of the site navigation */' menu ' = + Array ('  menu[1] ' = = Array (      ' headnav ' + ' Control Panel ',      ' subnav ' = + Array (         Array (' name ' = ' = ' Site Settings ', ' menumark ' = ' System ', ' url ' = ' system/index '),         Array (' name ' = ' = ' navigation management ', ' Menuma RK ' + ' Nav ', ' url ' = ' + ' nav/navlist '),         Array (' name ' = ' + ' ad management ', ' menumark ' = ' Show ', ' url ' = = ' Show/sho Wlist '),         Array (' name ' = = ' management list ', ' Menumark ' + ' admin ', ' url ' = = ' admin/adminlist '),),       ' menu[2] ' => ; Array (      ' headnav ' + ' single page management ',      ' subnav ' = = Array (         ' name ' = ' + ' single page Management ', ' menumark ' = ' ' page ', ' url ' = ' page/pagelist '),),      

    Change the configuration array so that the template's loop label is correct.


    I changed the method to the next no problem, the array loop out, thank you!
  • 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.