HTML Table Class :: showing up as text on view? |
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 |
Messages In This Thread |
HTML Table Class :: showing up as text on view? - by birdsaloon - 11-16-2019, 12:16 PM
RE: HTML Table Class :: showing up as text on view? - by ciadmin - 11-16-2019, 01:47 PM
RE: HTML Table Class :: showing up as text on view? - by birdsaloon - 11-16-2019, 02:01 PM
|