CodeIgniter Forums

Full Version: HTML Table Class :: showing up as text on view?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 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;


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->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)
echo view('templates/navagation');


And the view as shown below the line:  test.php


<!DOCTYPE html>
<meta charset="UTF-8">
<title>Title of the document</title>

<div class="w3-padding w3-display-middle">





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">

&lt;table border="0" cellpadding="4" cellspacing="0"&gt;



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 -

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')
2) Your very long post would be easier to read with bbcode ;P ...
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!