Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Html Table Using YII Framework

Tags:

php

yii

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.

like image 972
Noman Riffat Avatar asked Apr 09 '14 04:04

Noman Riffat


1 Answers

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.

like image 119
Alex Avatar answered Sep 29 '22 03:09

Alex