Friday, May 1, 2015

Html Helper: Better way to generate table ?

<?php
echo $this
->Html->tag( 'table', null, array( 'class' => 'table table-hover table-condensed' ) );
echo $this
->Html->tag( 'thead' );
echo $this
->Html->tableHeaders( array( 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine' ) );
echo $this
->Html->useTag( 'tagend', array( 'thead' ) );
echo $this
->Html->tag( 'tbody' );
echo $this
->Html->tableCells( array(
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
) );
echo $this
->Html->useTag( 'tagend', array( 'tbody' ) );
echo $this
->Html->useTag( 'tagend', array( 'table' ) );
?>

OR

<table class="table table-hover table-condensed">
<thead>
<?php echo $this->BsHtml->tableHeaders( array( 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine' ) ); ?>
</thead>
<tbody>
<?php echo $this->BsHtml->tableCells( array(
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
    array
( 1,2,3,4,5,6,7,8,9 ),
) ); ?>
</tbody>
</table>


It should be a better way to generate table without building a custom helper. Isn't it ?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: