2010-12-03 10 views
0

는 다음과 같은 오류 해결하는 방법에 대한 조언을 할 수 배열로 형 모델의 개체를 사용할 수 없습니다 :KOHANA - ErrorException [치명적인 오류] :

ErrorException [ Fatal Error ]: Cannot use object of type Model_Branch as array

참조하십시오를 컨트롤러 :


public function action_view($agent_id='') { 
     $agent = ORM::factory('agent', $agent_id); 

     if ($agent->loaded()) { 

      $values = $agent->as_array(); 
      $branches = $agent->branches->find_all()->as_array(); 

      // Show page 
      $this->template->title = $agent->company_name; 
      $this->template->content = View::factory('agent/view') 
        ->bind('title', $this->template->title) 
        ->bind('values', $values) 
        ->bind('branches', $branches); 
     } else { 
      Request::instance()->redirect('agent'); 
     } 
    } 
+0

예외를 던지는 부분을 표시하십시오. 컨트롤러가 아닌 컨트롤러처럼 보입니다. – biakaveron

답변

0

실제로 as_array()가 필요하지 않습니다. Database_Result 객체는 기본적으로 배열로 동작하므로 foreach ($branches as $b) echo $b->id을 배열로 변환하지 않고도 수행 할 수 있습니다.

Database_Result implements Countable, Iterator, SeekableIterator, ArrayAccess 

Database_Result의 유일한 현재 사용 :: as_array() 메소드는 내가 here을 지적, 키 => 발 배열을 생성하는 것입니다. 현재 seems logical at first이지만 데이터베이스 결과 배열로 변환 할 수 없습니다.

+0

고마워 kemo. as_array를 종료했습니다. – drs

0

나는 이것을 시도 할 것이다 :

$branches = $agent->branches->find_all(); 
$branches = $branches->as_array(); 

가끔은 당신이 선언 할 필요가있다. 그것을 변형시키기 전에.