Is there a Zend Helper to generate a Html Table using and array as input ?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
There is no native table zend view helper. However, you could use partialLoop view helper to ease generation of tables.
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
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:
or...
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:
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.
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.