我有以下模型:
class Model_Job extends ORM
{
public $ID;
public $user_ID;
public $title;
//some more variables
}
在我的控制器中,我有一个功能action_view()
;查看工作详情单个工作,实现方式与http://kohanaframework.org/3.3/guide/orm/using#finding-an-object完全相同
public function action_view()
{
$this->render('Shit');
$this->template->content = View::factory('jobs/job')
->bind('job', $job);
$job = ORM::factory('job', $this->request->param('id'));
}
我有另一个函数action_all()
,它简单地获取所有使用的作业find_all
并将它们放在页面上,这很好用(意味着echo $job->ID
它应该做的事情;回显 ID。但是action_view()
没有。我将放置一些输出echo Debug::vars($job)
object Model_Job(39) {
public ID => NULL //Note they are NULL
public user_ID => NULL
public title => NULL
......................
protected _object => array(5) (
"ID" => string(1) "1"
"user_ID" => string(1) "1"
"title" => string(14) "Testbaantjeeee"
................
)
.....................
}
echo Debug::vars($job)
而from的示例action_all()
如下所示:
object Model_Job(39) {
public ID => 1 //Note they are NOT NULL
public user_ID => 1
public title => "Testbaantjeeee"
......................
protected _object => array(5) (
"ID" => string(1) NULL //now these are NULL
"user_ID" => string(1) NULL
"title" => string(14) NULL
.....................
)
.....................
}
我查看了 kohena 的关于factory
,等的文档find
,find_all
但无法弄清楚正在做什么factory
或find
没有做什么find_all
。我错过了什么吗?我让它工作使用:
$job = ORM::factory('job')
->where('ID', '=', $this->request->param('id'))
->find_all()[0];
但这样做对我来说完全没有意义。我错过了什么?