•TOC
Ex.2: Using gridFor our grid example we use a little modified template 3.1. We use table layout and add some template elements.
If we examine this template, we found just a few news. There is new element pager. It will be transformed into clickable selector of pages, if we have long list of data. Attribute size tells how many page-links should be shown and another attribute pglen set length of page to 30 rows.Another new element is class. It is used for global configuration of whole grid. Here, only internal name of the grid is set. Behind this elements we can see two string elements. We already know them from basic template. There is a new attribute lb which define label of the field. It will replace template tag {NAME.lb} and {PRICE.lb}, respectively. You can use labels for almost any element types. These dot-separated tag modificators are used in another cases too. Try {pager.next}, {pager.prev}, {pager.total} etc. See also reference guide for complete list of tags and modificators. Moreover in field NAME is attribute sort. It marks column NAME as sortable. {NAME.lb} will be replaced with clickable link, which sorts the grid. If you want sorting by the PRICE too, add sort atribute to this field. Now, the code.
Pretty easy, isn't it? At third line we connect to database and register database object as $pclib->db, so grid can access it. Second parameter of grid constructor ('productlist') is optional. If present, grid state (such as current sort column, selected page and filter) will be stored into session, so you can go through pages and don't loose grid settings. PClib rarely stores anything into session, and most of features will work without session enabled. In our example, grid properties will be saved in $_SESSION['grid']['productlist'] variable. For more details about session storing, look at method grid::saveSession(). Method $page->setQuery() set datasource for the grid data. Here we get columns NAME and PRICE from PRODUCTS table, so you can use tags {NAME} and {PRICE} in template. You can apply filter on the grid by setting grid->filter property - see below.
Placeholders {MAXPRICE} and {CATEGORY} will be replaced with values from $productlist->filter array. If value for placeholder does not exists, whole line in SQL query will be omitted. Array $productlist->filter is stored in session, which means that filter will be remembered until you change it or delete whole filter by setting $productlist->filter = null; «PREV Basic template | Using form NEXT» |
VyhledáváníKam dál?Quickstart Malá ukázka použití jednotlivých komponent.Příručka Podrobnější popis použití jednotlivých tříd. V tuto chvíli pokrývá pouze tpl, form a grid. PClib App Začněte s šablonou pclib-app! Aktuální verze knihovny je 3.1.1. Changelog |