Skip to content
Nek- edited this page Nov 10, 2012 · 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
            url:         'http://www.my-website.com'
            language:    'fr'
            filename: "blog.|format|"

The filename is the name of your generate final file. The localisation of files is defined by a parameter: "nekland_feed.feeds.base_path" and the default value is "%kernel.root_dir%/../web/feeds"

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');

This initialize the 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 this is the default value, and if you extend the bundle you can use another loader

You can also load an atom_file or both (recommanded if you use the AtomInterface). This load your file in memory. After that you can use orther methods on the feed you load.

  1. Get the feed (here "post") and add, remove or replace the item you want.
// Get an object "Feed" who contains your feed "post"
$feed = $factory->get('post');
$feed->add($post); // add an ItemInterface to your feed
$feed->remove($id); // Remove an item with his id
$feed->replace($id, $post); // Replace an item identified by his id with the given item
  1. Render ! The following instruction save your feed in a file (who is specified in configuration)
$factory->render('post', 'rss'); // we want to render the feed into rss format but you can use the atom format
Clone this wiki locally