2010-12-03 7 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を指摘したように、キー=> valのアレイを生成するであろう。現在のところ、これはseems logical at firstですが、これをデータベース結果の配列に変換することはできません。

+0

それを修正した感謝kemo。 as_arrayを終了しました – drs

0

私はこれをしようとするだろう:

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

それがうまくいくかもしれない、時にはあなたが宣言する必要がありますそれを変換する前に