Array To String error / undefined $query |
There are various ways to solve this.
One way is introducing a 3rd parameter for the render function, e.g.: PHP Code: protected function render($the_view = NULL, $template = 'master', $data = NULL ) From you controller, call the function with the 3 parameters: PHP Code: $this->render('admin/docs/existing_view', NULL, $data); But remember to check all calls to the render function in all your controllers.
08-16-2016, 12:52 PM
(This post was last modified: 08-16-2016, 01:26 PM by CodinMoldovanu. Edit Reason: UPDATED ERRORS )
Even more errors!
Code: A PHP Error was encountered (08-16-2016, 12:52 PM)CodinMoldovanu Wrote: Even more errors! The render() method in Admin_controller should have the same signature with render() method in MY_Controller. In the model, use $query->result() In the view, revise the following line: PHP Code: foreach ($query as $row) // not $query->result()
Just make sure that the render function in the Admin_Controller has the same number and type of parameters as in MY_Controller. Right now, they are incompatible because one function has only 2 parameters, and the other one (with the same name), has 3 parameters. They must have the same structure.
Code: A PHP Error was encountered MY_Controller Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); Controller Code: public function existing() // Recieved, Unsolved Code: <table> Quote:Controller PHP Code: //...
I really think you need to redesign the render functions in both your MY_Controller class as the Admin_Controller class. Because Admin_Controller extends MY_Controller, they must have the same set of parameters.
Now, from your controller, you not only wish to pass the view and template, but also some data that has been collected from your database (via a Model). This requires a third parameter for both render functions. Simplified example: Controller: PHP Code: $data['query'] = $this->Docs_model->viewexisting(); MY_Controller (class MY_Controller AND class Admin_Controller!!!): PHP Code: public function render($view = 'default_view', $template = 'default_template', $data = NULL); $data is an array. In this example, it only contains the 'query' element, but you can pass as many elements in one $data array as you want. The $data array is automatically exploded to seperate variables when it's passed to a view. So in the view, you can refer to $query. If $query itself is an array (in this case it's an array of objects), you can loop through it's elements with foreach(...). Hope this will help you. |
Welcome Guest, Not a member yet? Register Sign In |