Trying to Get Property of Non-Object - Codeigniter

Trying to get property of non-object - CodeIgniter

To access the elements in the array, use array notation: $product['prodname']

$product->prodname is object notation, which can only be used to access object attributes and methods.

Code Igniter - Trying to get property of a non object

Hope this will help you :

Since u r using single item with object in your controller,So you should use row() instead of result_array();

Your model should be like this :

public function get($id) 
{
$results = $this->db->get_where('products', array('pro_id' => $id));
return $results->row();
}

Your controller should be like this :

Print $data in your controller to check it has data;

public function add() 
{
$id = $this->input->post('id');
$product = $this->products_model->get($id);

$data = array(
'id' => $id,
'name' => $product->pro_name,
'qty' => 1,
'price' => $product->pro_price
);
print_r($data); die();
$this->cart->insert($data);
}

For more : https://www.codeigniter.com/user_guide/database/results.html

How to solve Message: Trying to get property of non-object error in Codeigniter?

do like this

$get_bank =   $this->FD_Model->get_bank_by_branch($branch_list[0]->bankid);

AND

'br_bank' => $get_bank[0]->bank_name # this will work maybe

or

'br_bank' => $get_bank[0]['bank_name']

Its 0 indexed array so you need to add the key to access the child's

Trying to get property of non-object using codeigniter

change this in your model
$rows = $query->result_array();

and also use if(isset){} to check for empty

Severity: Notice Trying to get property of non-object and did not get any data from database table codeigniter

I did not get product_id.I forgot to name the 'product_id' in my view page.When i placed the name='product_id' in view page, this actually solved the problem.



Related Topics



Leave a reply



Submit