Message: Trying to get property of non-object in fuel cms

edited May 2012 in Modules
I am getting error in my view file as "Message: Trying to get property of non-object in fuel cms" . Where am i going wrong

Controller.php

function index()
{
if(!empty($this->data) && isset($this->data)) {
$vars['data']= $this->data;
$vars['gdata']= $this->list_stock();
}
else {
redirect(fuel_url('#'));
}
}
function list_stock() {

$this->load->model('stock_details_model');
$gdata = $this->stock_details_model->list_items();
$gdata['table'] = $this->stock_details_model->list_items();
return $gdata;


}

Views :
<?php
foreach($gdata as $folder) {
?>
stocknumber ?>')"><?=$folder->stocknumber ?>
<?php
}

?>

Model : (stock_details_model)
in list items method there is a query which gets the stock of entire unit

Comments

  • edited May 2012
    Can we see the complete files? Sure you're returning an array of objects and not arrays?

    By the looks of that $vars['gdata'] is going to be an array of objects (or arrays) keyed with 'table'.
    Is the second $gdata['table'] = ... there a mistake?

    if not what does:
    foreach ($gdata['table'] as $folder) { # If returning arrays $folder['stocknumber']; # If returning objects $folder->stocknumber; }

    Do for you?

    Your models list_items() method seems a bit of an odd choice for this too.
  • edited 5:06PM
    That message sometimes happens if your record class name in your model isn't properly set. Do you have the following in your model class:
    class Stock_detail_model extends Base_module_record { }
  • edited 5:06PM
    yes it works thanks lance and admin,
    it was a problem with the return type
Sign In or Register to comment.