View Generics
View generics are an easy way to generate commonly used HTML structures with fully custom data content. View generics are extensions of Alloy\View\Template with custom methods added to more easily render custom content where needed.
Most view generics use PHP 5.3 closures to enable the use of fully custom content blocks with native PHP code, just like for normal views. Using PHP closures in this way eliminates the need for custom template syntax or tags, parsers, or using template partials in a loop. As a result, closure templates are both much more efficient, and easy to use because there is no new syntax beyond what is already required by PHP 5.3.
DataGrid
The datagrid view generic renders a full HTML table with custom columns and cell content through the use of closure templates.
No blog posts found.
"; }); // Render full HTML table for all items echo $table->content(); ?>DataGrid Generated HTML
The resulting HTML from the above code for a datagrid assuming two blog posts in the dataset would produce the folowing HTML:
Title | Published | Edit | Delete |
---|---|---|---|
"app_datagrid_cell">New Blog Post | "app_datagrid_cell">Mar 02, 2011 | "app_datagrid_cell">"http://localhost/projects/alloy-example-blog/www/blog/1/edit" title="edit">edit | "app_datagrid_cell">"http://localhost/projects/alloy-example-blog/www/blog/1/delete" title="delete">delete |
"app_datagrid_cell">Alloy Generics are Awesome! | "app_datagrid_cell">Mar 02, 2011 | "app_datagrid_cell">"http://localhost/projects/alloy-example-blog/www/blog/2/edit" title="edit">edit | "app_datagrid_cell">"http://localhost/projects/alloy-example-blog/www/blog/2/delete" title="delete">delete |