Zend table html helper

2020-06-30 03:28发布

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

4条回答
唯我独甜
2楼-- · 2020-06-30 03:47

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

查看更多
forever°为你锁心
3楼-- · 2020-06-30 03:50

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

查看更多
一纸荒年 Trace。
4楼-- · 2020-06-30 03:55

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.

查看更多
混吃等死
5楼-- · 2020-06-30 04:03

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.

查看更多
登录 后发表回答