CodeIgniter Forums

Full Version: [solved]header view won't display correctly
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is like super easy question. There's a function in my controller which won't display correctly.
The header view will display below table which make characters unreadable due to missing encoding.
Please see code below. Please kindly advice what I missed.

public function show_registered(){

       $query = $this->db->get('registered');
       $data = array();
       $data[] = array('ลำดับที่','ภาพถ่าย');
       foreach($query->result() as $row){
           $image_properties = array(
               'src' => $row->photo,
               'width' => '180',
               'height' => '120',

           $data[] = array($row->id,img($image_properties));
       echo $this->table->generate($data);
9 out of 10 times your missing an html closing tag in your template files some place. which you did not post here.
You should not have echo and calls to $this->load->view() within the same controller (in general, you should not use echo in a controller). Save the result of $this->table->generate($data) to a value which you can then pass to a view, or generate the table within the view.

To go into more detail: $this->load->view() buffers the output until your controller relinquishes control back to the framework, which also allows CI's Output class to perform some additional processing. By calling echo within the controller, you place data into the output stream outside of (before) the buffered views.

Libraries and/or helpers which generate portions of HTML are usually intended to be used within your views or to have their output passed to views via variables, not to generate output directly from your controllers.
CI's view output is buffered, so if you echo something from the controller it will appear BEFORE the rest of your view. As stated, don't echo from a controller. Instead that should be another view.