在thinkphp模板中循环数组没循环出所需要的数据

WBOY
Release: 2016-06-13 12:24:27
Original
877 people have browsed it

在thinkphp模板中循环数组没有循环出所需要的数据
我在项目配置文件config.php里面写了个数组,代码

<br />/*网站左侧栏目导航*/<br />	'menu' => array(<br />	   'headnav' => '控制面板',<br />	   'subnav' => array(<br />		array('name' => '系统设置', 'menumark' => 'System', 'url' => 'System/index'),<br />		array('name' => '导航管理', 'menumark' => 'Nav', 'url' => 'Nav/navList'),<br />		array('name' => '广告图片', 'menumark' => 'Show', 'url' => 'Show/showList'),<br />		array('name' => '管理列表', 'menumark' => 'Admin', 'url' => 'Admin/adminList'),<br />	   ),<br />	),<br />
Copy after login

在模板里面的代码是这样的,如下:
<br /> <foreach name='menu' key='k' item='v'><br />						<div class="fenlei"><br />				<h3 class="fl_tb6"><s></s>{$v.headnav}</h3><br />				<ul >                  <volist name='v["subnav"]' key='k2' id='v2'><br />										<li><a href="">{$v2.name}</a></li><br />										</volist><br />						  </ul><br />				<div class="clear"></div><br />			</div><br />			</foreach><br />
Copy after login

郁闷死个人,我以前写过另外一个框架,可以用,但是移植到thinkphp就不行了。
------解决思路----------------------
你搞错了循环的对象,修改的部分代码参考如下:
			<h3 class="fl_tb6"><br />				<s></s><if condition='$k eq "headnav"'>{$menu["headnav"]}</if><br />			</h3><br />			<if condition='$k EQ "subnav"'><br />                <ul ><br />                	<volist name='$menu["subnav"]' key='k2' id='v2'><br />                        <li><a href="">{$v2.name}</a></li><br />                    </volist><br />                </ul><br />            </if>
Copy after login

------解决思路----------------------
在config.php里面正确定义数组应该是这样的:
<br />/*网站左侧栏目导航*/<br />	'menu' => array(<br />	  'menu[1]' => array(<br />	      'headnav' => '控制面板',<br />	      'subnav' => array(<br />		         array('name' => '网站设置', 'menumark' => 'System', 'url' => 'System/index'),<br />		         array('name' => '导航管理', 'menumark' => 'Nav', 'url' => 'Nav/navList'),<br />		         array('name' => '广告管理', 'menumark' => 'Show', 'url' => 'Show/showList'),<br />		         array('name' => '管理列表', 'menumark' => 'Admin', 'url' => 'Admin/adminList'),<br />		       )<br />			 ),<br />	 'menu[2]' => array(<br />	      'headnav' => '单页面管理',<br />	      'subnav' => array(<br />		         array('name' => '单页面管理', 'menumark' => 'Page', 'url' => 'Page/pageList'),<br />		       )<br /><br />	      ),<br />	 ),<br />
Copy after login

改下配置数组就可以了,模板的循环标签是正确的。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!