Prev | Current Page 67 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Let??™s assume that for our web site, we want the five most recent news items that have been created
within the last three months displayed on the home page. This could be done using $news->fetchAll() in
the home page controller, but it is better to move the logic down into the News model to maintain the correct
layering of the application and so that it can be reused by other controllers if required:
public function fetchLatest($count = 5)
{
$cutOff = date('Y-m-', strtotime('-3 months'))
$where = "date_created > '$cutOff'";
$order = "date_created DESC";
return $this->fetchAll($where, $order, $count);
}
Again, very simple functionality, that becomes much more powerful when placed in the right layer of the
M-V-C triumvirate.
2.7 Summary
We have now written a simple hello world application using the Zend Framework and have explored the way
the Model-View-Controller design pattern is applied to our applications. You should now have a good idea
about what the Zend Framework gives us for making our applications maintainable and easy to write.
One key ideal that the framework developers try to adhere to is known as the 80/20 rule. Each component
is intended to solve 80% of the problem space it addresses, whilst providing flex points to enable those
developers needing the other 20%.


Pages:
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
agencja reklamowa poznań nieruchomości szczecin opony samochodowe A*Teens Accept