제 삼항 연산자 할당이 제 배열의 두 번째 부분에서 작동하지 않습니다. 누구든지 내가 뭘 잘못하고 있는지 알아? 그 permalink 필드에 대한 값이 있는지 그리고 단지 배열에 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입니다 .- 그렇다면 매우 최적화 될 수 있습니다 _ –