2010-06-15 56 views
0

我有一个点击量,文章和分类表
现在,击中belongs_to文章/类别(取决于它在哪里完成)。
所以我在Hits表上有一个名字为'parenttype'的列
这告诉我'Article'或'Category'。
我在打击模型(扩展ORM)试图在Kohana,关系问题模型

protected $_belongs_to= array(
    'page' => array('model'=> $this->parenttype) 
    ); 

现在抱怨这个 - $写道> ParentType的不正常吗?

回答

1

你应该声明变量protected $ _belongs_to = NULL;

,并在构造函数中设置它调用父类的构造

public function __construct() { 
    parent::__construct(); 
    $this->_belongs_to = array('page' => array('model' => $this->parenttype)); 
} 
+0

工作就像一个魅力后的价值,我想我现在明白了。 – Asaf 2010-06-16 08:45:41

0

如果对象即将被实例化,你打算如何访问$ this? (即使你可以,$这个 - > ParentType的绝对还未关系之前加载了)

这意味着你需要定义关系一些其他的方式,一点点后:) (我仍不很像你这样做的方式)