Controller Code
Before we can make an RSS version of our posts/index we need to get a few things in order. It may be tempting to put the channel metadata in the controller action and pass it to your view using the Controller::set() method but this is inappropriate. That information can also go in the view. That will come later though, for now if you have a different set of logic for the data used to make the RSS feed and the data for the html view you can use the RequestHandler::isRss() method, otherwise your controller can stay the same.
Простой текст// Modify the Posts Controller action that corresponds to// the action which deliver the rss feed, which is the// index action in our examplepublic function index(){if( $this->RequestHandler->isRss() ){$posts = $this->Post->find('all', array('limit' => 20, 'order' => 'Post.created DESC'));$this->set(compact('posts'));} else {// this is not an Rss request, so deliver// data used by website's interface$this->paginate['Post'] = array('order' = 'Post.created DESC', 'limit' => 10);$posts = $this->paginate();$this->set(compact('posts'));}}
With all the View variables set we need to create an rss layout.


Коментарии:
Добавить коментарий