Prev | Current Page 105 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

The field in the database is in ISO format (YYY-MM-DD hh:mm:ss) which is
not very friendly to the user of the website. Whilst we could convert directly in the template, using a view
helper, as shown in listing 3.11, ensures that we are consistent in our display of dates and makes it easier to
change that display should the client want a different format.
Listing 3.11: View helper to ensure all dates are displayed consistently.
class ZFiA_View_Helper_DisplayDate
{
function displayDate($time, $format='%d %B %Y') #1
{
$timestamp = strtotime($time); #2
return strftime($format, $timestamp);
}
}
(annotation) <#1 Allow for override of the default format for special cases.>
(annotation) <#2 use strtotime() to remove dependency on the format of the $time variable.>
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
Although we use strtotime() to ensure that the $time variable can be in pretty much any format, be aware
that it can get confused between UK and US short dates of the format dd/mm/yyyy and mm/dd/yyyyy! We
have now completed the first page of the website and Places is ready to have bells and whistles added to it.
3.5 Summary
This chapter has introduced a real application, Places to take the kids, which will be expanded upon throughout
the rest of the book as we discuss all the components of the Zend Framework.


Pages:
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
ABBA prezenty skrzynki do internetu Danny Hotel Berlino