Home > Backend Development > PHP Tutorial > ThinkPHP使用volist模板赋值有关问题

ThinkPHP使用volist模板赋值有关问题

WBOY
Release: 2016-06-13 12:25:36
Original
1129 people have browsed it

ThinkPHP使用volist模板赋值问题
今天看代码遇到个问题,给模板赋值是用

assign('变量名','变量值')
Copy after login
完成的吧,模板那边
<volist name="变量名" id="循环量">xxx<br />        </volist>
Copy after login


但是我遇到了变量名好像不一样啊。
<ul class="main-nav"><br />        <volist name="__MENU__.main" id="menu"><br />        <li class="{$menu.class|default=''}"><a href="{$menu.url|U}">{$menu.title}</a></li><br />        </volist><br />    </ul>
Copy after login

$this->assign('__MENU__', $this->getMenus());
Copy after login


这个多出来的.main是个啥?新人求解答
------解决思路----------------------
__MENU__是一个数组,__MENU__.main也就相当于__MENU__['main']
再说的明白一点,假设数组$a=array('main'=>array(1,2,3)),$a.main也就是$a['main'],也就是array(1,2,3)。
------解决思路----------------------
php5.4+ 可以这样
<br />assign(__MENU__,getMenus()['main'])<br />
Copy after login

若小php5.4版本
就这样
<br />$tmp=getMenus();<br />assign(__MENU__,$tmp['main'])<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