Prev | Current Page 100 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

We will add a new function fetchLatest() to the Places class which will automatically order the results
by reverse date of update as shown in listing 3.7.
Listing 3.7: The Places model implements fetchLatest() to ensure the business logic is kept in the correct layer.
class Places extends Zend_Db_Table
{
function fetchLatest($count = 10)
{
return $this->fetchAll(null, |#2
'date_created DESC', $count); |
}
}
(annotation) <#1 The results are ordered by reverse date and are limited to $count records.>
Zend_Db_Table??™s fetchAll() function returns a Zend_Db_Table_Rowset which can be iterated over using
the foreach() construct in our view template. In listing 3.8, we assign it to the view within indexAction().
Listing 3.8 The IndexController??™s indexAction displays a list of the places that have most recently been added.
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->title = 'Browse places'; #1
$placesFinder = new Places(); |#2
$this->view->places = $places->fetchLatest(); |
}
}
(annotation) <#1 Set the title for the web browser??™s title bar.>
(annotation) <#2 .Use the model to collect the recently created places and assign to the view.>
The IndexController??™s indexAction function is quite simple as all it does is assign a couple of member
variables to the view.


Pages:
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
zakłady bukmacherskie polish courses warsaw Wczasy nad morzem buchsbaum loans with no credit check