Installation
Add the bundle to your composer.json:
composer require avro/blog-bundle
Enable it in config/bundles.php:
return [
// ...
Avro\BlogBundle\AvroBlogBundle::class => ['all' => true],
];
Configuration
Add the required config to config/packages/avro_blog.yaml:
avro_blog:
db_driver: mongodb # Only supported option
list_count: 10 # Posts per page
Routing
Import routes in config/routes.yaml:
avro_blog:
resource: "@AvroBlogBundle/Resources/config/routing/routing.yml"
First Use Case
/blog to see a paginated list of posts.Post Management
// Example (hypothetical) service call to create a post
$this->get('avro_blog.post_manager')->create([
'title' => 'Hello World',
'content' => '...',
'published_at' => new \DateTime(),
]);
Avro\BlogBundle\Entity\Post (if available) to add custom fields:
use Avro\BlogBundle\Entity\Post as BasePost;
class ExtendedPost extends BasePost {
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customField;
}
Pagination
use Knp\Component\Pager\PaginatorInterface;
$posts = $this->get('knp_paginator')->paginate(
$this->get('avro_blog.post_repository')->findAll(),
$this->getParameter('avro_blog.list_count')
);
Templating
templates/blog/:
{# app/Resources/AvroBlogBundle/views/Post/index.html.twig #}
{% extends 'AvroBlogBundle:Post:index.html.twig' %}
{% block post_content %}
{{ post.content|raw }} <!-- Customize rendering -->
{% endblock %}
Event Listeners
// src/EventListener/BlogListener.php
class BlogListener {
public function onPostPublish(PostPublishEvent $event) {
// Add logic (e.g., send notification)
}
}
Register in services.yaml:
services:
App\EventListener\BlogListener:
tags:
- { name: 'kernel.event_listener', event: 'avro_blog.post_publish' }
MongoDB Dependency
doctrine_mongodb bundle is properly configured:
doctrine_mongodb:
connections:
default:
server: '%mongodb_uri%'
options: {}
Lack of Documentation
src/Resources/config/routing/routing.yml for route paths.src/Entity/Post.php for entity structure.src/DependencyInjection/ for configuration logic.No Active Maintenance
KnpPaginatorBundle Dependency
knp-paginator-bundle is installed and configured:
composer require knplabs/knp-paginator-bundle
Check Routes Dump available routes to verify integration:
php bin/console debug:router | grep avro_blog
MongoDB Queries Log queries to debug issues:
doctrine_mongodb:
logging: true
Template Overrides Clear cache after overriding templates:
php bin/console cache:clear
Custom Post Fields
Extend the Post entity (if possible) or create a one-to-one relationship:
// src/Entity/CustomPostData.php
class CustomPostData {
// Add fields here
}
Link it to the post entity:
// In Post.php
/**
* @ORM\OneToOne(targetEntity="CustomPostData", mappedBy="post", cascade={"persist", "remove"})
*/
private $customData;
Custom Repository Override the default repository for complex queries:
// src/Repository/CustomPostRepository.php
class CustomPostRepository extends ServiceEntityRepository {
public function findPublishedWithTags(string $tag) {
// Custom logic
}
}
Update services.yaml:
services:
Avro\BlogBundle\Repository\PostRepository:
alias: 'App\Repository\CustomPostRepository'
Event Dispatching If the bundle lacks events, create your own:
// src/Event/PostEvent.php
class PostEvent extends Event {
protected $post;
// ...
}
Dispatch manually in controllers/services:
$event = new PostEvent($post);
$this->get('event_dispatcher')->dispatch($event, 'avro_blog.post_publish');
Form Integration If the bundle uses forms, extend them:
// src/Form/PostTypeExtension.php
class PostTypeExtension extends AbstractTypeExtension {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('customField', TextType::class);
}
}
Register the extension:
services:
App\Form\Extension\PostTypeExtension:
tags:
- { name: form.type_extension, extended_type: Avro\BlogBundle\Form\PostType }
How can I help you explore Laravel packages today?