由于某种原因,我的三元运算符分配不适用于我的数组的第二部分。任何人看到我做错了什么?它应该只是看看是否有永久链接字段的值,如果没有,然后将link_url
插入到数组中。内联三元运算符不工作
function getSiteMap()
{
$this->db->select('site_menu_structures_links.id, site_menu_structures_links.link_name');
$this->db->from('site_menu_structures_links');
$this->db->where('site_menu_structures_links.status_id', 1);
$this->db->where('site_menu_structures_links.is_category', 'Yes');
$this->db->order_by('site_menu_structures_links.sort_order');
$catQuery = $this->db->get();
if ($catQuery->num_rows())
{
foreach ($catQuery->result() as $cats)
{
// Set the Main Category into the array
$testArray[$cats->id] = array(
'id' => $cats->id,
'name' =>$cats->link_name
);
$this->db->select('site_content_pages.permalink, site_menu_structures_links_children.id, site_menu_structures_links_children.link_url, site_menu_structures_links_children.link_name');
$this->db->from('site_menu_structures_links_children');
$this->db->join('site_content_pages', 'site_content_pages.id = site_menu_structures_links_children.site_content_pages_id');
$this->db->where('site_menu_structures_links_id', $cats->id);
$this->db->where('site_menu_structures_links_children.status_id', 1);
$this->db->order_by('site_menu_structures_links_children.sort_order');
$childrenQuery = $this->db->get();
if ($childrenQuery->num_rows())
{
foreach ($childrenQuery->result() as $child)
{
$testArray[$cats->id]['children'][$child->id] = array(
'linke_url' => (empty($child->permalink)) ? $child->link_url : $child->permalink,
'link_name' => $child->link_name,
);
}
}
}
}
return $testArray;
}
编辑:
也不应该有社会阵列及其不是说里面有3项。我想知道它是否与该连接有关。这里是我的输出:
Array
(
[2] => Array
(
[id] => 2
[name] => Roster
[children] => Array
(
[1] => Array
(
[linke_url] =>
[link_name] => Superstars
)
[2] => Array
(
[linke_url] =>
[link_name] => Champions and Contenders
)
[3] => Array
(
[linke_url] =>
[link_name] => Title History
)
)
)
[3] => Array
(
[id] => 3
[name] => Events
[children] => Array
(
[4] => Array
(
[linke_url] =>
[link_name] => Preview Next Event
)
[5] => Array
(
[linke_url] =>
[link_name] => Latest Event Results
)
[6] => Array
(
[linke_url] =>
[link_name] => Event Archives
)
[7] => Array
(
[linke_url] =>
[link_name] => Schedule An Event
)
)
)
[4] => Array
(
[id] => 4
[name] => Media
[children] => Array
(
[8] => Array
(
[linke_url] =>
[link_name] => Photo Gallery
)
)
)
[5] => Array
(
[id] => 5
[name] => Social
)
)
什么不行? –
它应该是'linke_url'吗?你大概不会试图访问'link_url'或其他东西,这是一个错字?我看不到任何错误的代码,除了我以为它会因为$ child-> link_name后的逗号而出错,但它可能不会。你有没有得到任何PHP错误,在这种情况下可能值得注意的错误类型'NOTICE'。 –
此外,我是否明白,您正在尝试构建类别的层次结构,并且“site_menu_structures_links_id'是内部引用'site_menu_structures_links.id'的父ID,如果是,可以_massively optimised_ –