Array To String error / undefined $query |
I'm learning CodeIgniter 3 and have come to a halt because of a (probably) stupid thing I did. Could you help me in identifying the issue in my code?
I'm trying to display some rows of data from a database and I get this error Quote:A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: core/MY_Controller.php Line Number: 24 Backtrace:My Controller Code: public function existing() // Recieved, Unsolved Code: public function viewexisting() Code: <?php foreach($query as $row){?> Help? Please?
The error seems to be in your MY_Controller file, which is most likely in your application/core folder.
Please check what it does at line 24.
Your return your query as an object not an associated array change $query->result() to $query->result_array()
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-14-2016, 03:31 PM)InsiteFX Wrote: Your return your query as an object not an associated array change $query->result() to $query->result_array()Did so, got this error. Code: A PHP Error was encountered
(08-14-2016, 10:41 AM)Wouter60 Wrote: The error seems to be in your MY_Controller file, which is most likely in your application/core folder. Code: class MY_Controller extends CI_Controller Code: $this->load->view('templates/'.$template.'_view', $this->data);
If your using the $data array in your MY_Controller then you need to call it using $this->data
PHP Code: public function viewexisting() What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
In your controller, you are calling the render method like this:
PHP Code: $this->render('admin/docs/existing_view', $data); However, in your MY_Controller, the render function expects a string as the second parameter: PHP Code: protected function render($the_view = NULL, $template = 'master') That's why you are getting the array to string conversion error.
(08-16-2016, 10:46 AM)Wouter60 Wrote: In your controller, you are calling the render method like this: Thank you for your answer! What should I do then? |
Welcome Guest, Not a member yet? Register Sign In |