[eluser]Unknown[/eluser]
Hello, I've only been using Codeigniter for 24 hours (apologies for stupid questions etc.)
The controller code below displays a simple table of contacts from a MySQL database. I have standard header and footer views I'm using, as I'm doing everything with the table and database classes, I
thought it made sense to keep the DB query and table writing code in the controller rather than in the view - however the trouble with the current output is the table is output *before* the header and footer.
(a) Is my methodology wrong - should *any* HTML output always be written in the view, even if that makes I end up with a large block of ugly PHP code amongst my HTML tags?
(b) is there some way to flush the output buffer after loading views etc. in exceptional circumstances?
Code:
function index() {
$data['title'] = "Group Contacts";
$this->load->view('header.php', $data);
$this->load->library('table');
$query = $this->db->get('local_group_contacts');
if ($query->num_rows() > 0) {
$this->table->set_heading('Area', 'Contact', 'Telephone');
foreach ($query->result() as $row) {
$this->table->add_row($row->area, $row->fullname, $row->tel);
}
echo $this->table->generate();
}
$this->load->view('footer.php', $data);
}
Secondly, the HTML Table class seems a bit limited - apparently no support for 'scope' attributes, opening/closing <thead>,<tfoot>,<tbody>, and adding class tags or other attributes to specific cells. Has someone somewhere written a better one?
Thanks,
William