I am just new to YII framework and know very basics of YII like CRUD etc.
I just want to create HTML Tables using YII. Following is mine VIEW code where I rendered an array $results
and it contains all records that I want to be shown using HTML Table
<?php
/* @var $this RrCimyUefDataController */
/* @var $model RrCimyUefData */
$this->breadcrumbs=array(
'Rr Cimy Uef Datas'=>array('index'),
'Create',
);
?>
<table>
<tr>
<th>Serial Number</th>
<th>Business Name</th>
<th>Facebook</th>
<th>Twitter</th>
</tr>
<?php
for($a=0, $b=1;$a<count($results);$a=$a+3,$b++){
if(($a+1)<count($results) && ($a+2)<count($results)){
echo '<tr><td>'.$b.'</td>';
echo '<td>'.$results[$a].'</td>';
echo '<td>'.$results[$a+1].'</td>';
echo '<td>'.$results[$a+2].'</td></tr>';
}
}
//var_dump($results);
?>
</table>
The code is working fine but it is not done through proper YII methods. Thank you in advance.
You can use CGridView and CArrayDataProvider for rendering grid, but it will give you some additional functionality, there is no helper that just renders simple table in Yii. Also you can use
echo CHtml::openTag('table');
echo CHtml::openTag('tr');
echo CHtml::tag('th', array(), 'Serial Number'); // for hable head
...
echo CHtml::closeTag('tr');
echo CHtml::openTag('tr');
echo CHtml::tag('td', array(), $results[$a+1]); // for cells
echo CHtml::closeTag('tr');
If you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With