Skip to content
Nek- edited this page Aug 26, 2011 · 17 revisions

Configuration

The FeedBundle needs to be configured to recognized your feeds. This is an exemple of possible configuration:

nekland_feed:
    feeds:
        post:
            class:        Nekland\BlogBundle\Entity\Post
            title:       'My fabulous posts'
            description: 'Here are my very fabulous posts'
            # usally the homepage
            route:       'home'
            language:    'fr'
            filename: "blog.rss"

In this case we are using a model as item class for the feed. We have to declare it. You must implement ItemInterface:

    class Post implements ItemInterface
    {
        // Implement the needed methods
    }

Configuration is over. You can make feeds when you want. Usually they are using in a controller.

Using FeedBundle in a controller

  1. Get the feed factory:

     $factory = $this->get('nekland_feed.factory');
    
  2. Load a feed:

     // "post" is the name of the feed in the configuration
     $factory->load('post', 'rss_file');
     // For this example we are using rss_file but it is the default value, and if you extends the bundle you can use another loader
    
  3. Get the feed (here "post") and add, remove or replace what item you want.

     $feed = $factory->get('post');
     $feed->add($post); // adding an ItemInterface
     $feed->remove($id); // Remove an item with his id
     $feed->replace($id, $post); // Replace an item identified by his id by the item given
    
  4. Render !

     $factory->render('post', 'rss'); // we want render the feed into rss format
    
Clone this wiki locally