Php 在CodeIgniter解析器类中添加额外级别的解析数组
我为我的站点提供了一个导航菜单,我使用了一系列链接来使用CodeIgniter的解析器类构建它。当我想添加下拉菜单的子菜单时,就会出现问题。变量对的第一级就可以了,除了它总是在列表项中显示一个子ul元素,而不管是否有子菜单链接 当我使用这个数组时,子菜单的ul元素设置正确,但是子菜单的链接都没有解析,因为它缺少额外的级别。如何修改CI解析器类以解析额外级别的数组 这是我的菜单php数组:Php 在CodeIgniter解析器类中添加额外级别的解析数组,php,arrays,codeigniter,Php,Arrays,Codeigniter,我为我的站点提供了一个导航菜单,我使用了一系列链接来使用CodeIgniter的解析器类构建它。当我想添加下拉菜单的子菜单时,就会出现问题。变量对的第一级就可以了,除了它总是在列表项中显示一个子ul元素,而不管是否有子菜单链接 当我使用这个数组时,子菜单的ul元素设置正确,但是子菜单的链接都没有解析,因为它缺少额外的级别。如何修改CI解析器类以解析额外级别的数组 这是我的菜单php数组: $data['navigation_links'] = array( array(
$data['navigation_links'] = array(
array(
'href' => site_url('home'),
'title' => 'My Home Page',
'target' => '',
'text' => 'Home',
'submenu' => array()
),
array(
'href' => site_url('blog'),
'title' => 'My Blog',
'target' => '',
'text' => 'Blog',
'submenu' => array()
),
array(
'href' => site_url('portfolio'),
'title' => 'My Portfolio',
'target' => '',
'text' => 'Portfolio',
'submenu' => array(
'submenu_links' => array(
array(
'sub_href' => site_url('portfolio/gallery'),
'sub_title' => 'Photography Gallery',
'sub_target' => '',
'sub_text' => 'Photography Gallery'
),
array(
'sub_href' => site_url('portfolio/web-projects'),
'sub_title' => 'Web Projects',
'sub_target' => '',
'sub_text' => 'Web Projects'
)
)
)
),
array(
'href' => site_url('services'),
'title' => 'My Services',
'target' => '',
'text' => 'Services',
'submenu' => array()
),
array(
'href' => site_url('resume'),
'title' => 'My Resume',
'target' => '',
'text' => 'Resume',
'submenu' => array()
),
array(
'href' => site_url('about'),
'title' => 'About Me',
'target' => '',
'text' => 'About',
'submenu' => array()
),
array(
'href' => site_url('contact'),
'title' => 'Contact Me',
'target' => '',
'text' => 'Contact',
'submenu' => array()
)
);
这是视图文件的菜单部分:
<nav class="container">
<ul>
{navigation_links}
<li><a href="{href}" title="{title}"{target}>{text}</a>
{submenu}
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
{submenu_links}
<li><a href="{sub_href}" title="{sub_title}"{sub_target}>{sub_text}</a></li>
{/submenu_links}
</ul>{/submenu}</li>
{/navigation_links}
</ul>
</nav>
{导航链接}
-
{子菜单}
{子菜单链接}
{/子菜单\链接}
{/子菜单}
{/导航链接}
这是HTML输出:
<nav class="container">
<ul>
<li><a href="http://localhost/scotthlacey/index.php/home" title="My Home Page">Home</a>
</li>
<li><a href="http://localhost/scotthlacey/index.php/blog" title="My Blog">Blog</a>
</li>
<li><a href="http://localhost/scotthlacey/index.php/portfolio" title="My Portfolio">Portfolio</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
{submenu_links}
<li><a href="{sub_href}" title="{sub_title}"{sub_target}>{sub_text}</a></li>
{/submenu_links}
</ul></li>
<li><a href="http://localhost/scotthlacey/index.php/services" title="My Services">Services</a>
</li>
<li><a href="http://localhost/scotthlacey/index.php/resume" title="My Resume">Resume</a>
</li>
<li><a href="http://localhost/scotthlacey/index.php/about" title="About Me">About</a>
</li>
<li><a href="http://localhost/scotthlacey/index.php/contact" title="Contact Me">Contact</a>
</li>
</ul>
</nav>
-
-
-
{子菜单链接}
{/子菜单\链接}
-
-
-
-
尝试将另一级别的数组包装到子菜单链接。因为您的数据(要迭代的每个数组)必须是多维数组才能通过解析器进行迭代
$data['navigation_links'] = array(
array(
'href' => site_url('home'),
'title' => 'My Home Page',
'target' => '',
'text' => 'Home',
'submenu' => array()
),
array(
'href' => site_url('blog'),
'title' => 'My Blog',
'target' => '',
'text' => 'Blog',
'submenu' => array()
),
array(
'href' => site_url('portfolio'),
'title' => 'My Portfolio',
'target' => '',
'text' => 'Portfolio',
'submenu' => array(
array(
'submenu_links' => array(
array(
'sub_href' => site_url('portfolio/gallery'),
'sub_title' => 'Photography Gallery',
'sub_target' => '',
'sub_text' => 'Photography Gallery'
),
array(
'sub_href' => site_url('portfolio/web-projects'),
'sub_title' => 'Web Projects',
'sub_target' => '',
'sub_text' => 'Web Projects'
)
)
)
)
),
array(
'href' => site_url('services'),
'title' => 'My Services',
'target' => '',
'text' => 'Services',
'submenu' => array()
),
array(
'href' => site_url('resume'),
'title' => 'My Resume',
'target' => '',
'text' => 'Resume',
'submenu' => array()
),
array(
'href' => site_url('about'),
'title' => 'About Me',
'target' => '',
'text' => 'About',
'submenu' => array()
),
array(
'href' => site_url('contact'),
'title' => 'Contact Me',
'target' => '',
'text' => 'Contact',
'submenu' => array()
)
);
希望它对你有用