![]() |
Array To String error / undefined $query - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Array To String error / undefined $query (/showthread.php?tid=65943) Pages:
1
2
|
Array To String error / undefined $query - CodinMoldovanu - 08-14-2016 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? RE: Array To String error / undefined $query - Wouter60 - 08-14-2016 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. RE: Array To String error / undefined $query - InsiteFX - 08-14-2016 Your return your query as an object not an associated array change $query->result() to $query->result_array() RE: Array To String error / undefined $query - CodinMoldovanu - 08-15-2016 (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 RE: Array To String error / undefined $query - CodinMoldovanu - 08-15-2016 (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); RE: Array To String error / undefined $query - pdthinh - 08-16-2016 Please show full content of docs/existing_view.php RE: Array To String error / undefined $query - CodinMoldovanu - 08-16-2016 (08-16-2016, 12:02 AM)pdthinh Wrote: Please show full content of docs/existing_view.php Code: <?php I tried result_array and got the $query undefined error. RE: Array To String error / undefined $query - InsiteFX - 08-16-2016 If your using the $data array in your MY_Controller then you need to call it using $this->data PHP Code: public function viewexisting() RE: Array To String error / undefined $query - Wouter60 - 08-16-2016 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. RE: Array To String error / undefined $query - CodinMoldovanu - 08-16-2016 (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? |