我正在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