Reputation: 13
I want to write new route for RSS-View. The call /news/index.rss must open the RSS-Feed, but it open wrong methode.
routes.php
Router::parseExtensions('rss');
...
// don't work
Router::connect('/news/index.rss', array('controller' => 'news', 'action' => 'index'));
...
// open News:indexForPage()
Router::connect('/news/indexForPage/*', array('controller' => 'news', 'action' => 'indexForPage'));
...
// List width pagignation (News:index())
Router::connect('/news/*/:slug/:page',
array(
'controller' => 'news',
'action' => 'index'
),
array(
'competence_id'=>'[a-z,0-9,A-Z,\-]+',
'page'=>'[a-z,0-9,A-Z,\-]+'
)
);
...
// After call '/news/{Title-of-the-Article}-{ID}', it open News:view(ID)
Router::connect('/news/**', array('controller' => 'news', 'action' => 'view'));
That are all rules width "/news".
And wenn I call in browser "localhost/news/index.rss", it open News:view(), but not News:index(). If I deactivate the last line, it works, but I need this line.
How can I correct it?
Upvotes: 1
Views: 46
Reputation: 13
I accepted the answer from drmonkeyninja quickly and not tested all functions.
I'm pleased width actually functions, but it is not perfect.
What I want, what I have, and what works:
My code:
routes.php
// RSS-Feed. See point 1.
Router::connect('/news/index.rss', array('controller' => 'news', 'action' => 'index', 'ext' => 'rss'));
// See point 2. localhost/news/index
Router::connect('/news/index', array('controller' => 'news', 'action' => 'index'));
// It is for other methode. It works, and it isn't interesting.
Router::connect('/news/indexForPage/*', array('controller' => 'news', 'action' => 'indexForPage'));
// It is easy. localhost/news/view/{NEWS-ID} See point 4.
Router::connect('/news/view/*', array('controller' => 'news', 'action' => 'view'));
// localhost/news/{NEWS-TITLE}-{NEWS-ID} See point 4.
Router::connect('/news/*', array('controller' => 'news', 'action' => 'view'));
// My alternative solution for point 3. (e.g. localhost/breaking-news/3 It works fine with filter and AJAX-pagignation.)
Router::connect('/breaking-news/*/:slug/:page',
array(
'controller' => 'news',
'action' => 'index'
),
array(
'competence_id'=>'[0-9]+',
'page'=>'[a-z,0-9,A-Z,\-]+'
)
);
NewsController.php
class NewsController extends AppController {
public $helpers = array('Paginator');
public $components = array('RequestHandler', 'Paginator');
/**
* See points 1-3.
* @param string $competence_id
*/
public function index($competence_id = NULL) {...}
/**
* It isn't interesting.
* @param int $count
* @param int $sector
*/
public function indexForPage($count = NULL, $sector = NULL) {...}
/**
* See point 4.
* @param string $id
*/
public function view($id = NULL) {...}
}
Points for betterment are welcome:
Upvotes: 0
Reputation: 8540
You need to add 'ext' => 'rss'
to your route as you are using Router::parseExtensions('rss');
:-
Router::connect(
'/news/index.rss',
array('controller' => 'news', 'action' => 'index', 'ext' => 'rss')
);
Upvotes: 1