1. Go to this page and download the library: Download laravelium/feed library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
laravelium / feed example snippets
use Rumenx\Feed\FeedFactory;
class FeedController extends Controller
{
public function feed()
{
$feed = FeedFactory::create();
$feed->setTitle('My Blog Feed');
$feed->setDescription('Latest posts from my blog');
$feed->setLink('https://example.com');
$feed->addItem([
'title' => 'First Post',
'author' => 'Rumen',
'link' => 'https://example.com/post/1',
'pubdate' => now(),
'description' => 'This is the first post.'
]);
// Return XML string directly
$xml = $feed->render('rss');
return response($xml, 200, [
'Content-Type' => 'application/xml'
]);
}
}
use Rumenx\Feed\FeedFactory;
class FeedController extends Controller
{
public function feed()
{
$feed = FeedFactory::create();
$feed->setTitle('My Blog Feed');
$feed->addItem([
'title' => 'First Post',
'author' => 'Rumen',
'link' => 'https://example.com/post/1',
'pubdate' => now(),
'description' => 'This is the first post.'
]);
// Get data for your own view template
$items = $feed->getItems();
$channel = [
'title' => $feed->getTitle(),
'description' => $feed->getDescription(),
'link' => $feed->getLink()
];
return response()->view('feed.rss', compact('items', 'channel'), 200, [
'Content-Type' => 'application/xml'
]);
}
}
use Rumenx\Feed\FeedFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class FeedController extends AbstractController
{
public function feed(): Response
{
$feed = FeedFactory::create();
$feed->setTitle('My Blog Feed');
$feed->setDescription('Latest posts from my blog');
$feed->setLink('https://example.com');
$feed->addItem([
'title' => 'First Post',
'author' => 'Rumen',
'link' => 'https://example.com/post/1',
'pubdate' => new \DateTime(),
'description' => 'This is the first post.'
]);
// Return XML response
$xml = $feed->render('atom');
return new Response($xml, 200, ['Content-Type' => 'application/xml']);
}
}
class FeedController extends AbstractController
{
public function feed(): Response
{
$feed = FeedFactory::create();
$feed->setTitle('My Blog Feed');
$feed->addItem([
'title' => 'First Post',
'author' => 'Rumen',
'link' => 'https://example.com/post/1',
'pubdate' => new \DateTime(),
'description' => 'This is the first post.'
]);
// Get data for your own Twig template
$items = $feed->getItems();
$channel = [
'title' => $feed->getTitle(),
'description' => $feed->getDescription(),
'link' => $feed->getLink()
];
return $this->render('feed/atom.xml.twig', [
'items' => $items,
'channel' => $channel
], new Response('', 200, ['Content-Type' => 'application/xml']));
}
}
use Rumenx\Feed\Feed;
$feed = new Feed([
'cache' => new MyCacheAdapter(),
'config' => new MyConfigAdapter(),
'response' => new MyResponseAdapter(),
'view' => new MyViewAdapter(),
]);
$feed->setTitle('My Feed');
$feed->addItem([
'title' => 'Hello',
'author' => 'Rumen',
'link' => 'https://example.com/hello',
'pubdate' => date('c'),
'description' => 'Hello world!'
]);
// Use render() for framework-specific response
// or render() for XML string in plain PHP
echo $feed->render('rss');
// Create feed with simple adapters (recommended for most users)
$feed = FeedFactory::create($config);