Welcome Guest, Not a member yet? Register   Sign In
[solved]header view won't display correctly
#1

(This post was last modified: 03-12-2015, 07:45 PM by naminator.)

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.

Code:
public function show_registered(){
       $this->load->database();
       $this->load->helper('form');
       $this->load->helper('url');    
       $this->load->library('table');
       $this->load->helper('html');

       $this->load->view('template/header');
       
       $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);
       $this->load->view('template/footer');        
   }
Reply
#2

9 out of 10 times your missing an html closing tag in your template files some place. which you did not post here.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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.
Reply
#4

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB