2014-11-20 4 views
0

는 내가 어떤 페이지 PARENT_ID없이 데이터베이스에서 레코드를 가져 오기 위해 원하거나 우리가

.. 부모없이 페이지 모델 을 페이지를 말할 수 ..........

public function get_no_parents() { 
// fecth pages wihtout parents 
$this->db->select ('id','title'); 
$this->db->where ('parent_id', 0); 
$pages = parent::get(); 
// if there are pages then return key as page->id and value $page->title 
$array = array (
0 => 'no parent' 
); 

if(is_array($pages)){ 

foreach ($pages as $page){ 

$array[$page->id]=$page->title; 
    $return $array; 


    } 
    } 
} 

................................

..... 페이지 컨트롤러

$this->data['pages_no_parents']=$this->Page_model->get_no_parents(); 
    var_dump($this->data['pages_no_parents']); 

.... 덤프가 null입니다. 두 개의 오류가 있습니다.

,

1 정의되지 않은 속성 : foreach는 대한 공급 stdClass : $ 제목

2 잘못된 인수()

누군가가 나를 도울 수

?

+0

'return $ array; – Brewal

+0

여전히 문제가 존재합니다 – syedsafir

+0

여전히 * a * 문제가 있지만 다른 것이 있습니다. 'parent :: get();'은 무엇을 반환합니까? – Brewal

답변

1

변경 :

$this->db->select ('id','title'); 

사람 :이 도움이

$this->db->select ('id, title'); 

희망!

+1

그것이 작동했는지, 나에게 설명 할 수 있습니까? 그들 사이의 차이는 무엇입니까? – syedsafir

+0

'$ this-> db-> select()'는 2 개의 매개 변수만을 취합니다 : 1) 선택 문자열 2) 문자열을 이스케이프해야 하는지를 나타내는 플래그. 그래서'('id', 'title')을 가지고있을 때 select의 일부로 전달되는 문자열은'id'뿐입니다. –

관련 문제