Hello, i have some trouble on getting a data from a related table. I have checked everything but it seems all is already right according to the tutorial, so i need your help on figuring what's wrong with it.
The generated error:
Fatal error: Call to undefined method Phalcon\Mvc\Model\Resultset\Simple::getUser() in ...(my view page line 10)...
Here's the code :
Controller:
public function indexAction()
{
$data = BrowsingItem::find(array("order" => "dateAdded"));
$this->view->setVar("data", $data);
}
View:
{{ content() }}
{% for data in page.items %}
{% if loop.first %}
<div id="h-list">
{% endif %}
<div id="h-item">
Supplier : {{ data.getUser().name }}
Item Name : {{ data.itemName }}
Description : {{ data.desc }}
Price : {{ "%.2f"|format(data.price) }}
Date Added : {{ data.dateAdded }}
</div>
{% if loop.last %}
<div class="btn-group">
//Paging things
</div>
{% endif %}
</div>
{% else %}
No products are recorded
{% endfor %}
Model (BrowsingItem):
class BrowsingItem extends Model{
public $itemID;
public $supplierID;
public $itemName;
public $desc;
public $photo;
public $price;
public $discount;
public $stock;
public $dateAdded;
public $views;
public $liked;
public $itemStatus;
public function initialized(){
$this->skipAttributes(array('itemID', 'dateAdded', 'views', 'liked', 'itemStatus'));
$this->belongsTo("supplierID", "User", "userID");
}
}
Model (User):
class User extends Model{
public $userID;
public $password;
public $name;
public $email;
public $phone;
public $city;
public $postal;
public $joinDate;
public $balance;
public $accStatus;
public function initialize(){
$this->skipAttributes(array('userID', 'joinDate', 'balance', 'accStatus'));
$this->hasMany("userID", "BrowsingItem", "supplierID");
}
}
Thanks in advance :D