我正在cakephp项目中工作。实际上我有表menu_items
在数据库中,其中包含id
,parent_id
,title
,url
和is_active
。我的父母菜单项正常显示,但问题出现在与parent_id
有关的子菜单中。保留第一列(即id)的值并与同一表中另一列(即parent_id)的所有值匹配php
foreach($menusitems as $menu)
{
if($menu['MenuItem']['is_active'] == true)
{
echo $this->Html->link($menu['MenuItem']['title'], array('controller' => 'pages', action' => $menu['MenuItem']['url']));
foreach ($menu['MenuItem'] as $temp)
{
if($id == $temp['parent_id'])
{
echo "match";
}
}
}
}
这不是一个正确的代码,我只是想匹配特定的ID(例如:1)想匹配与第一父ID的每个值去那么我要在那里找到匹配的价值,我必须打印值在子菜单列表中的标题以及与下一个标识符相同的过程(例如:2)等等。但我与父母id的匹配ID不起作用。
When i use
'echo "<pre>"
print_r($menus);
echo "</pre>"
'
'Array
(
[id] => 1
[parent_id] =>
[title] => Home
[url] => home
[is_active] => 1
)
Array
(
[id] => 2
[parent_id] =>
[title] => Profile
[url] =>
[is_active] => 1
)
Array
(
[id] => 3
[parent_id] =>
[title] => Home
[url] => home
[is_active] => 1
)
Array
(
[id] => 4
[parent_id] => 2
[title] => Bussiness Profile
[url] => bussiness_profile
[is_active] => 1
)'
我只是想显示商业作为配置文件下的子菜单。如果id与1相等,则我匹配。如果任何父母身份证在我的案例中存在,如“商务资料”,那么该项目应显示为配置文件的子菜单。
是什么“这是不是一个正确的代码”是什么意思?听起来你想用[find('threaded')](http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find-threaded) - 很难说。 – AD7six
我编辑了一些代码,希望对你来说足够了。 – user2314433