johnlemon
johnlemon

Reputation: 21509

Zend table html helper

Is there a Zend Helper to generate a Html Table using and array as input ?

Upvotes: 0

Views: 4303

Answers (4)

Stoyan Dimov
Stoyan Dimov

Reputation: 5549

You can also use a PEAR's HTML_Table package. You can throw an array to the table class and it is gonna populate the table for you. It has some nice features like colouring odd and even lines, set parameters per row, per columns and per table body.

Find more info at http://pear.php.net/package/HTML_Table/docs/latest/HTML_Table/HTML_Table.html

Upvotes: 0

ischenkodv
ischenkodv

Reputation: 4255

Most of all I use partialLoop() to generate tables. But sometimes, for simple data that don't require formatting, I use my simple view helper: https://gist.github.com/812481 . Usage:

<?php echo $this->table()->setRows($rows); ?>

or...

<?php echo $this->table(null, $rows); ?>

The $rows can be associative array or any object that has toArray method (Zend_Db_Table_Rowset, Doctrine_Collection etc.). Following is more complicated example, with headers, caption, additional column:

echo $this->table()
  ->setCaption('List of something')
  ->setAttributes(array('class' => 'mytable', 'id' => 'currenciesList'))
  ->setColumns(array(
          'currency' => 'Currency',
          'rate' => 'Rate',
          'edit_options' => ''  // Custom column
      ))
    // content for custom column.
  ->setCellContent(
      '<a href="/currency/delete/{id}" class="deleteLink">Delete</a>', 'edit_options'
      )
  ->setFooter('Something to write in footer...')
  ->setEmptyRowContent('Nothing found')
  ->setRows($rows);

But this approach is not as convenient as partialLoop, cause it takes input data and display it as is - it doesn't allow you to format values using Zend_Date, Zend_Currency or do custom cell formatting.

Upvotes: 2

Stephen Fuhry
Stephen Fuhry

Reputation: 13039

partialLoop() is probably best if you need a lightweight, easily customizable table generator. If you want something a little more to take all but the business logic of report generation in Zend, take a look at zfdatagrid.

Upvotes: 2

Marcin
Marcin

Reputation: 238957

There is no native table zend view helper. However, you could use partialLoop view helper to ease generation of tables.

Upvotes: 1

Related Questions