kohana property error
i have a kohana module, describing a table that has a reference to another table. So i declare in the 'Sale' module:
protected $_belongs_to = array(
'image' => array('foreign_key' => 'sale_picture_header'),
);
and then, in a get method, i say:
public function __get($property)
{
blah blah
.......
if ($property == 'image')
{
ret开发者_高级运维urn $this->image;
}
and then i call in a view
<? $image = $sale->image->find(); ?>
but i get a weird error :
Notice: Undefined property: Model_Sale::$image in ...
(in the model) where i declare $this-> image (so it doesn't actually recognise this property an i wonder why)
why is that? the property is defined. am i missing something?
thank you!
Assuming your question is about ORM models
There is no need to modify __get()
method, because ORM will automatically return table columns and relations by their names. Just use $sale->image
(without ->find()
) and you get a related model.
精彩评论