App Directory >> CakePHP RSS + XML + Time by Ajay Anturkar
CakePHP RSS + XML + Time
RSS Helper
- The RSS helper makes generating XML for RSS feeds easy.
Sample View File
$rss = get::helper('rss');
if (!isset($documentData)) {
$documentData = array();
}
if (!isset($channelData)) {
$channelData = array();
}
if (!isset($channelData['title'])) {
$channelData['title'] = "Test title";
}
$documentData = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/');
$channelData= array(
'title' => 'Most Recent Posts',
'link' => 'http://www.yourwebsite.com/path/',
'description' => 'Test Description.',
'language' => 'en-us');
$content_for_layout=$rss->item(array(), array(
'title' => 'Test Title ',
'link' => 'http://www.yourwebsite.com',
'guid' => array('url' => 'http://www.yourwebsite.com', 'isPermaLink' => 'true'),
'description' => 'Test Description',
'creator' => 'Creator Name',
'pubDate' => '2011-06-25 07:12:16'));
$channel = $rss->channel(array(), $channelData, $content_for_layout);
echo $rss->document($documentData,$channel);
Time Helper
It allows for the quick processing of time related information. The Time Helper has two main tasks that it can perform:
- It can format time strings.
- It can test time.
- Uses "CakePHP i18n + l10n" component by Diogo ResendeDiogo Resende with some modifications
Functions
- fromString( $date_string )
- toQuarter( $date_string, $range = false )
- toUnix( $date_string )
- toAtom( $date_string )
- toRSS( $date_string )
- nice( $date_string = null )
- niceShort( $date_string = null )
- daysAsSql( $begin, $end, $fieldName, $userOffset = NULL )
- dayAsSql( $date_string, $field_name )
- timeAgoInWords( $datetime_string, $options = array(), $backwards = null )
- gmt( $date_string = null )
- format( $format = 'd-m-Y', $date_string)
How to use Time Helper
$time = get::helper('time');
echo $time->nice('1206975600');// Output: Mon, Mar S 2008, 10:00
XML Helper
The XML Helper simplifies the output of XML documents.
- serialize($data, $options = array())
echo $this->Xml->serialize($data);
- string elem (string $name, $attrib = array(), mixed $content = null, $endTag = true)
echo $this->Xml->elem('count', null, array('cdata'=>true,'value'=>'content'));
- header(): This method is used to output the XML declaration
echo $this->Xml->header();