2011-12-05 2 views
0

왜 비 객체의 속성을 얻으려고하는지 알기 위해 노력하고 있습니다. 나는 객체와 배열에 대해 완전히 숙련 된 사람은 아니지만 노력하고 있습니다. 여기에 코드와 오류 메시지가 있습니다. 이 문제를 해결하는 방법에 대한 아이디어가 있습니까?비 객체의 속성

A PHP Error was encountered 

Severity: Notice 

Message: Trying to get property of non-object 

Filename: models/sitemodel.php 

Line Number: 208 and 215 



function getSubMenuPages() 
{ 
    $this->db->select('site_menu_structures.id'); 
    $this->db->from('site_menu_structures'); 
    $this->db->where('site_menu_structures.short_name', 'mainnav'); 
    $query = $this->db->get(); 
    $menu_id = $query->row()->id; 

    $this->db->select('site_menu_structures_links.id, site_menu_structures_links.short_name, is_category'); 
    $this->db->from('site_menu_structures_links'); 
    $this->db->where('site_menu_structures_links.menu_structure_id', $menu_id); 
    $query = $this->db->get(); 

    if ($query->num_rows() > 0) 
    { 
     $linksArray = $query->result(); 
     foreach ($linksArray as $key => $link) 
     { 
      if ($link->is_category == 'Yes') 
      { 
       $linksArray->{$key}->child_links; 
       $this->db->select('site_menu_structures_links_children.link_name'); 
       $this->db->from('site_menu_structures_links_children'); 
       $this->db->where('site_menu_structures_links_children.site_menu_structures_links_id', $link->id); 
       $query = $this->db->get(); 
       if ($query->num_rows() > 0) 
       { 
        $linksArray->{$key}->child_links = $query->result(); 
       } 
      } 
     } 
    } 

    return $linksArray; 

} 
+3

당신이 받고있는 정확한 오류 메시지를 게시 할 수 시도? –

+0

$ this-> db-> get(); 항상 객체를 반환합니까? ADOdb의 경우, 쿼리가 실패하면 false를 반환합니다. 따라서 if 문이'if ($ query && Query-> num_rows()) {' –

+0

과 같은 형태가되게 할 수 있습니다. 208 및 215 행에 플래그를 지정할 수 있습니까? 줄 번호 거 터가 없기 때문입니다. –

답변

3
$linksArray 것이 내 생각 엔 배열, 라인 그렇게하지 객체가

$ linksArray -> {$ 키} -> child_links;

은 작동하지 않습니다. 어쨌든,이 라인은 아무 것도하지 않으므로 왜 그렇게됩니까?

이 "속성"에 값을 할당

이 대신

$linksArray[$key]->child_links = $query->result(); 
0

"비 개체의 속성을 얻으려고 노력"

하면 객체 인스턴스로 변수를 처리하려고하면 오류의 종류 만 존재하고 실제로 성공적으로 인스턴스를 만들 확인하려고 실패 코드의이 부분이 실제로 객체인지 아닌지 :

$linksArray->{$key}->child_links 

이것은 코드 하단에 있습니다.

관련 문제