I'm pretty new to CakePHP and i'm even pretty new to rss ... so i
followed the guide line by line found here:
http://book.cakephp.org/view/483/Creating-an-RSS-feed-with-the-RssHelper
But instead of using Post/Entry i used Article. Otherwise it's all
identical. However, it doesn't work. When i navigate to /articles/
index.rss the title of the feed shows up, but absolutely no data
shows.
I would guess that I'm doing something wrong, but is it possible that
there may be some misinfomation in the provided link?
Anyway, here's my code:
// controller
class ArticlesController extends AppController {
function index() {
if ($this->RequestHandler->isRss()) {
$articles = $this->Article->find('all', array('limit' => 20,
'order' => 'Article.created DESC'));
$this->set(compact('articles'));
}
else {
$this->paginate['Article'] = array('order' => 'Article.created
DESC', 'limit' => 5);
$articles = $this->paginate();
$this->set(compact('articles'));
}
}
}
// /app/views/layouts/rss/default.ctp
<?php
echo $rss->header();
if (!isset($documentData)) {
$documentData = array();
}
if (!isset($channelData)) {
$channelData = array();
}
if (!isset($channelData['title'])) {
$channelData['title'] = $title_for_layout;
}
$channel = $rss->channel(array(), $channelData, $content_for_layout);
echo $rss->document($documentData, $channel);
?>
// /app/views/articles/rss/index.ctp
<?php
$this->set('documentData', array(
'xmlns:dc' => 'http://purl.org/dc/elements/1.1/'));
$this->set('channelData', array(
'title' => __("Saga News", true),
'link' => $html->url('/', true),
'description' => __("Saga News", true),
'language' => 'en-us'));
foreach ($articles as $article) {
$postTime = strtotime($article['Article']['created']);
$articleLink = array(
'controller' => 'articles',
'action' => 'view',
'year' => date('Y', $postTime),
'month' => date('m', $postTime),
'day' => date('d', $postTime),
$article['Article']['slug']);
App::import('Sanitize');
$bodyText = preg_replace('=\(.*?)\=is', '', $article['Article']
['body']);
$bodyText = $text->stripLinks($bodyText);
$bodyText = Sanitize::stripAll($bodyText);
$bodyText = $text->truncate($bodyText, 400, '...', true, true);
echo $rss->item(array(), array(
'title' => $article['Article']['title'],
'link' => $articleLink,
'guid' => array('url' => $articleLink, 'isPermaLink' => 'true'),
'description' => $bodyText,
'pubDate' => $article['Article']['created']));
}
?>
Thanks for any help :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---