Свежайшие Пирожки от CakePHP по-русски

Полнейшее руководство CakePHP 1.2 на русском языке, горячие новости и полезные статьи

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.

Простой текст
  1. // Modify the Posts Controller action that corresponds to
  2. // the action which deliver the rss feed, which is the
  3. // index action in our example
  4. public function index(){
  5. if( $this->RequestHandler->isRss() ){
  6. $posts = $this->Post->find('all', array('limit' => 20, 'order' => 'Post.created DESC'));
  7. $this->set(compact('posts'));
  8. } else {
  9. // this is not an Rss request, so deliver
  10. // data used by website's interface
  11. $this->paginate['Post'] = array('order' = 'Post.created DESC', 'limit' => 10);
  12. $posts = $this->paginate();
  13. $this->set(compact('posts'));
  14. }
  15. }

With all the View variables set we need to create an rss layout.