我有扩展 ORM 的 Model_Group。
我有获得新 ORM 的 Controller_Group:
public function before()
{
global $orm_group;
$orm_group = ORM::factory('Group');
}
...并且它有多种方法可以使用它来获取不同的数据子集,例如...
public function action_get_by_type()
{
global $orm_group;
$type = $this->request->param('type');
$result = $orm_group->where('type', '=', $type)->find_all();
}
然后我有另一个控制器(在一个单独的模块中),我想用它来操作对象并调用相关视图。我们称它为 Controller_Pages。
$orm_object = // Get the $result from Controller_Group somehow!
$this->template->content = View::factory( 'page1' )
->set('orm_object', $orm_object)
将 ORM 对象从 Controller_Group 传递到 Controller_Pages 的最佳方法是什么?这是一个好主意吗?如果不是,为什么不呢,还有什么更好的方法呢?
将它们分离到不同控制器的原因是因为我希望能够从其他模块中重用 Controller_Group 中的方法。每个模块可能希望以不同的方式处理对象。