Monday, February 22, 2010

Re: RSS without extension

A bit more info. RequestHandler is loaded in AppController.
PostsController::index() has:

public function index()
{
$this->pageTitle = 'Blog';

if($this->RequestHandler->isRss())
{
$posts = $this->Post->find(
'all',
array(
'limit' => 20,
'order' => 'Post.created DESC'
)
);
}
else
{
...
}
}

Router::parseExtensions('rss');
Router::connect(
'/blog/feed',
array('controller' => 'posts', 'action' => 'index', 'url' =>
array('ext' => 'rss'))
);

With this, I get the normal index view, whether I include the 'url'
param or not.


Mark Storey has a page[1] up where he says that parseExtensions() must
not be present if using 'url' param. So, I tried commenting that out
and it worked. Problem solved.

But I found some really strange things happening if I'm logged in as
an admin. I get this error:

Error: The layout file /var/www/vhosts/mim/app/views/layouts/rss/
admin.ctp can not be found or does not exist.
Error: Confirm you have created the file: /var/www/vhosts/mim/app/
views/layouts/rss/admin.ctp

When I change the route to:

Router::connect(
'/blog/feed',
array('controller' => 'posts', 'action' => 'index', 'admin' => 0,
'url' => array('ext' => 'rss'))
);


Error: The view for PostsController::admin_index() was not found.
Error: Confirm you have created the file: /var/www/vhosts/mim/app/
views/posts/rss/admin_index.ctp


The view at app/views/posts/rss/index.ctp exists.
The layout at app/views/layouts/rss/default.ctp exists.

And I only see this if I have debug = 2. When set to 0 I'd be
redirected to the regular index action. I placed a die('wtf?'); line
in every place where there's a redirect to index with no luck. I then
placed it in the else block inside index action. Still nothing. So
then I did this:

if($this->RequestHandler->isRss())
{
die('wtf?');

Bang! Cake quits and FF prompts me to either open or save feed (RSS
file). So, it's not that I was being redirected but that the incorrect
view is being rendered. So I tried $this->viewPath = 'posts/rss';
without luck. I then did $this->render('rss/index'); and get a message
saying that posts/rss/rss/index.ctp can't be found. Aaarrgghh! What
the flippity-frig is happening here?


Side note: I had debug disabled because router.php throws an array to
string conversion notice. It's due to the 'url' param in the route.
This is maddening!

$html->link(
$html->image('feed.png', array('width' => 14, 'height' => 14)),
array('controller' => 'posts', 'action' => 'index', 'url' =>
array('ext' => 'rss')),
array('id' => 'rss_feed', 'escape' => false)
)


[1] http://mark-story.com/posts/view/fancy-routing-examples-with-cakephp-1-2

On Feb 22, 12:23 am, cricket <zijn.digi...@gmail.com> wrote:
> I'm trying to set up RSS for my PostsController and I'd like to have
> extensionless URLs.Instead of using /blog/index.rss (which works, btw)
> I'd like to use /blog/feed for the RSS URL. I can't figure out why
> this isn't working:
>
> Router::parseExtensions('rss');
> Router::connect(
>         '/blog/feed',
>         array('controller' => 'posts', 'action' => 'index', 'url' =>
> array('ext' => 'rss'))
> );
>
> Router::connect(
>         '/blog/*',
>         array('controller' => 'posts')
> );
>
> Any ideas?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: