コントローラーに、次のように機能する条件付きフィルターを記述しました。
$this->_view = View::factory('crud/index')
->bind('collection', $collection);
$collection = ORM::factory($this->_model);
if (Request::current()->method() === Request::POST)
{
foreach (Request::current()->post('filter') as $field => $value)
{
$collection->where($field, '=', $value);
}
}
$collection->find_all();
ビューには、データベースにフィルタリングされた結果または行がない場合にメッセージを表示する条件があります。
<?php if ( ! $collection->count()): ?>
これは私に例外を与えます:
Kohana_Exception [ 0 ]: Invalid method count called in Model_Product
問題は、フィルターを追加する前のコントローラーのアクションが次のとおりだったことです。
$this->_view = View::factory('crud/index')
->bind('collection', $collection);
$collection = ORM::factory($this->_model)->find_all();
そして$collection->count()
、ビューでうまくいきました。コードが条件に入っていなくても、投稿していなくても ORM find_all() メソッドがモデルを返すのはなぜですか? $collection = ORM::factory($this->_model)->find_all();
侵入して全体$collection = ORM::factory($this->_model);
を壊すだけです。$collection->find_all();
なぜその奇妙な行動なのですか?ありがとう。