-
Notifications
You must be signed in to change notification settings - Fork 20
Basic use
Nek- edited this page Aug 26, 2011
·
17 revisions
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 ending. You can make feeds when you want. Usually they are using in a controller.
-
Get the feed factory:
$factory = $this->get('nekland_feed.factory');
-
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
-
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
-
Render !
$factory->render('post', 'rss'); // we want render the feed into rss format