Skip to content
Nek- edited this page Sep 4, 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.|format|"

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. They are generally used 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'); // you can also type atom_file
     // For this example we are using rss_file but this is the default value, and if you extend the bundle you can use another loader
    
  3. Get the feed (here "post") and add, remove or replace the item you want.

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

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