====== Step5. Adding more functionality: news detail page, 5 latest news on the main page, sorting etc. ====== ===== Sorting news ===== Let's suppose we need to sort news by "date" field. This can be accomplished in many different ways. One possible way is to set sorting properties by **order** attribute of tag right in the template: Another way is to call sort($params) method of newsline record set. You can use this method in case if you prefer using raw php-blocks in your templates: sort('date' => 'DESC'); ?> [...] One more way is to set default sorting parameters in News class: class News extends lmbActiveRecord { protected $_default_sort_params = array('date' => 'DESC'); } lmbActiveRecord :: $_default_sort_params allows you to set just default sorting params. If we passed any other sorting params using the first two methods - the default sorting params will be ignored. ===== The latest news on the main page ===== Now when we know how to sort news we can render some latest news on the main page of our application. To do so let's create (or modify) **crud/template/main_page/display.html** template:

Main page

{$date} {$title}
{$annotation} more...

all news...
Here we used **limit** attribute of tag. We can always limit the size of any record set fetched by tag with **limit** and **offset** attributes. There is an alternative way to apply limit and offset: sort('date' => 'DESC')->paginate($offset = 0, $limit = 3); ?> P.S. If you would like to see complete interface of news record set look at limb/core/src/lmbCollectionInterface.interface.php. lmbCollectionInterface is a common interface for all classes that implement collections (e.g. db record set or array holder lmbCollection). The next line: more... is responsible for rendering links to pages with detail description of news. If you started this tutorial with limb_app downloaded from SourseForge.net then you already have MainPageController. But if started this project from the scratch then you need to add a controller for the main page (**crud/src/controller/MainPageController.class.php**): ===== News detail page ===== Let's add new template **crud/template/news/detail.html** to render full information for some particular news:

{$title}

Date : {$date}
{$content|raw}
Please note **first** attribute of tag that means what we don't need a complete record set but just a single (first) record. tag accepts news object fetched by tag. [[limb3:en:packages:wact:tags:fetch_tags:fetch_parameter_tag|]] tag is used to pass some extra params to tag. In our case we used this tag to pass news identifier we need to load. The value of news identifier (id) we take from "request" - the request object with POST and GET data is available in the global scope in WACT template(this is done for you by WEB_APP package). {$#request.id} expression means: "use request from global scope then take 'id' attribute from request". We can always achieve the same result with raw php-block without using any WACT tag for fetching operations: get('request')->get('id')); ?>

{$title}

Date : {$date}
{$content|raw}
Or even without : get('request')->get('id')); ?>

{$$news.title}

Date : {$$news.date}
{$$news.content|raw}
The last point is to modify news/display.html a bit to render a link to news detail page as well as on the main page: [...] {$annotation} more... [...] ===== What's next? ===== * [[.step6|Step6. Creating newsline RSS-feed]]