• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTML Table Class :: showing up as text on view?

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

&lt;table border="0" cellpadding="4" cellspacing="0"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Color&lt;/th&gt;&lt;th&gt;Size&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Fred&lt;/td&gt;&lt;td&gt;Blue&lt;/td&gt;&lt;td&gt;Small&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;&lt;td&gt;Red&lt;/td&gt;&lt;td&gt;Large&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;&lt;td&gt;Green&lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

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

#2
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?a...help&hid=7
Reply

#3
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!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.