![]() |
HTML Table Class :: showing up as text on view? - 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: HTML Table Class :: showing up as text on view? (/showthread.php?tid=74861) |
HTML Table Class :: showing up as text on view? - birdsaloon - 11-16-2019 I am playing with the code for CI4 for the first time this weekend, I wanted to get familiar with the HTML class specifically the HTML Table Class. Using the information on your codeigniter4.github.io site I had tried to make a test page so see how this works with the code below: Test.php (Controller) below line: ------------------------------------------------------------------------------------------------------------------------------------------------ <?php namespace App\Controllers; use CodeIgniter\Controller; helper('array'); class Test extends Controller { public function index() { $parser = \Config\Services::parser(); $table = new \CodeIgniter\View\Table(); $template = [ 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', 'thead_open' => '<thead>', 'thead_close' => '</thead>', 'heading_row_start' => '<tr>', 'heading_row_end' => '</tr>', 'heading_cell_start' => '<th>', 'heading_cell_end' => '</th>', 'tfoot_open' => '<tfoot>', 'tfoot_close' => '</tfoot>', 'footing_row_start' => '<tr>', 'footing_row_end' => '</tr>', 'footing_cell_start' => '<td>', 'footing_cell_end' => '</td>', 'tbody_open' => '<tbody>', 'tbody_close' => '</tbody>', 'row_start' => '<tr>', 'row_end' => '</tr>', 'cell_start' => '<td>', 'cell_end' => '</td>', 'row_alt_start' => '<tr>', 'row_alt_end' => '</tr>', 'cell_alt_start' => '<td>', 'cell_alt_end' => '</td>', 'table_close' => '</table>' ]; $table->setTemplate($template); $table->setHeading('Name', 'Color', 'Size'); $table->addRow('Fred', 'Blue', 'Small'); $table->addRow('Mary', 'Red', 'Large'); $table->addRow('John', 'Green', 'Medium'); $mytable = $table->generate(); $data = [ 'table' => $mytable, ]; echo view('templates/topfooter'); echo $parser->setData($data) ->render('test'); echo view('templates/navagation'); } } ------------------------------------------------------------------------------------------------------------- And the view as shown below the line: test.php ------------------------------------------------------------------------------------------------------------- <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title of the document</title> </head> <body> <div class="w3-padding w3-display-middle"> {table} </div> </body> </html> ------------------------------------------------------------------------------------------------------------------ The end result I am getting is this: ------------------------------------------------------------------------------------------------------------------- <table border="0" cellpadding="4" cellspacing="0"> <thead> <tr> <th>Name</th><th>Color</th><th>Size</th></tr> </thead> <tbody> <tr> <td>Fred</td><td>Blue</td><td>Small</td></tr> <tr> <td>Mary</td><td>Red</td><td>Large</td></tr> <tr> <td>John</td><td>Green</td><td>Medium</td></tr> </tbody> </table> --------------------------------------------------------------------------------------------------------------------- When looking at the page source I am seeing this: ---------------------------------------------------------------------------------------------------------------------- <div class="w3-padding w3-display-middle"> <table border="0" cellpadding="4" cellspacing="0"> <thead> <tr> <th>Name</th><th>Color</th><th>Size</th></tr> </thead> <tbody> <tr> <td>Fred</td><td>Blue</td><td>Small</td></tr> <tr> <td>Mary</td><td>Red</td><td>Large</td></tr> <tr> <td>John</td><td>Green</td><td>Medium</td></tr> </tbody> </table> </div> ----------------------------------------------------------------------------------------------------------------------------- Any ideas on what I am doing wrong here? One thing I can say is when I set the $template array it seems nothing is showing up? So I think the framework is skipping that all together? I appreciate any input - Chris RE: HTML Table Class :: showing up as text on view? - ciadmin - 11-16-2019 Two things wrong: 1) using the template parser, you need to tell it not to escape the generated HTML, i.e. $parser->setData($data,'raw') ->render('test'); 2) Your very long post would be easier to read with bbcode ;P ... https://forum.codeigniter.com/misc.php?action=help&hid=7 RE: HTML Table Class :: showing up as text on view? - birdsaloon - 11-16-2019 My apologies, LOL. I am new to this forum. Actually forums in general. I am mainly solution miner using google. I read a solution and try to implement it. If it works great, if not I keep mining for a solution. After hours on google, I decided to try here. I will read the bbcode and I appreciate you giving me the heads up. Using the raw option worked. Thank you very much! |