I've this methods in a helper:
And use them in views this way:
Feel free to use if you find them useful ;)
El jueves, 7 de mayo de 2015, 22:12:35 (UTC+1), samuel escribió:
-- <?php
/*
* Boostrap table helpers
*/
public function full_table(array $headers, array $rows, array $footer, $table_class = 'table table-bordered table-condensed', $header_class = 'active', $footer_class = 'active') {
//style="white-space: normal; word-wrap: break-word; table-layout: fixed;
$content = '';
$content .= $this->Html->tag('table', null, array('class' => $table_class));
if (!empty($headers)) {
$content .= $this->Html->tag('thead', $this->Html->tableHeaders($headers, array('class' => $header_class)));
}
if (!empty($rows)) {
$content .= $this->Html->tag('tbody', $this->Html->tableCells($rows));
}
if (!empty($footer)) {
$content .= $this->Html->tag('tfoot', $this->Html->tableHeaders($footer, array('class' => $footer_class)));
}
$content .= $this->Html->tag('/table');
$content = $this->Html->div('table-responsive', $content);
return $content;
}
?>
And use them in views this way:
<?php
// Table headers
$headers = array();
$headers[] = __('Imagen');
$headers[] = $this->Paginator->sort('product_category_id', __('Categoría'));
// Table rows
$rows = array();
foreach ($products as $data) {
$row = array();
$row[] = $data['ProductCategory']['name'];
$row[] = $data['Product']['description'];
$row[] = $data['Product']['price'];
$rows[] = $row;
}
echo $this->Util->simple_table($headers, $rows);
?>
Feel free to use if you find them useful ;)
El jueves, 7 de mayo de 2015, 22:12:35 (UTC+1), samuel escribió:
nice! Is bshelper part of cakephp?
On Friday, May 1, 2015 at 9:54:43 PM UTC+1, Sylvain Lévesque wrote:
<?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:
Post a Comment