Load multiple models within same function of controller |
I have getting below error when I try to load two model in one view..
A PHP Error was encountered Severity: Notice Message: Undefined variable: i_price Filename: item/edit.php Line Number: 75 Backtrace: File: C:\wamp64\www\MY\admin\application\views\item\edit.php Line: 75 Function: _error_handler File: C:\wamp64\www\MY\admin\application\controllers\Item.php Line: 75 Function: view File: C:\wamp64\www\MY\admin\index.php Line: 315 Function: require_once My Model:- PHP Code: function update_view($id) Controller:- PHP Code: function update($id) Code: <!-- Content Wrapper. Contains page content --> Any one can help me for resolve this error?
Are you sure your getting the price back?
I don't see you doing any debugging to check for a price. PHP Code: $query = $this->db->query("SELECT price FROM price WHERE item_id='$id'"); You should always check to make sure that your getting back the values that you want. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
When I var_dump this variable like var_dump($data['$item_price_data']); die(); I can see the price come. But when I use it like this a have get this error..
Your assigning row an object for views if it is passed into a $data it is an associated array.
To view that in a CodeIgniter view you need to assign it in the Controller to a $data associated array. Try assigning $row = row_array(); You cannot just create a variable and access it in a view because they are not global. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
In your Model that's were you are returning it.
function item_price What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I think the problem lies here
PHP Code: $data['$i_price'] = $this->Item_model->item_price($id); Note the `$` in the string. Try this instead PHP Code: $data['i_price'] = $this->Item_model->item_price($id); The there will be a $i_price variable in the view (Assuming, as pointed out by others, the model returned something.) |
Welcome Guest, Not a member yet? Register Sign In |