Installation
composer require axstrad/content-bundle
Add to AppKernel.php:
new Axstrad\ContentBundle\AxstradContentBundle(),
First Use Case: Basic Content Model
Define a content entity (e.g., BlogPost) extending Axstrad\ContentBundle\Entity\Content:
use Axstrad\ContentBundle\Entity\Content;
class BlogPost extends Content
{
// Custom fields/methods
}
Run migrations:
php app/console doctrine:schema:update --force
Twig Integration
Enable Twig extensions in config.yml:
twig:
extensions: [Axstrad\ContentBundle\Twig\ContentExtension]
Use in templates:
{{ content('BlogPost', 1).title }}
CRUD Operations Use repository methods:
$repository = $this->getDoctrine()->getRepository('AxstradContentBundle:BlogPost');
$post = $repository->find(1); // Get by ID
$posts = $repository->findBy(['status' => 'published']); // Query builder
Content Types & Inheritance
Extend Content for reusable logic:
class Product extends Content
{
protected $price;
// ...
}
Twig Content Rendering Dynamic content blocks:
{% for block in content('Page', 1).blocks %}
{{ block.render() }}
{% endfor %}
API Integration
Use Axstrad\ContentBundle\Serializer\ContentNormalizer for API responses:
$serializer->serialize($content, 'json');
prePersist/preUpdate for validation:
$entityManager->getEventManager()->addEventListener(
ContentEvents::PRE_PERSIST,
[$this, 'validateContent']
);
doctrine-fixtures-bundle:
$fixture->addReference('homepage', new Page(['title' => 'Home']));
Legacy Symfony 2.3 Dependency
Twig Extension Conflicts
ContentExtension classes.config.yml:
twig:
extensions:
- ['Axstrad\ContentBundle\Twig\ContentExtension', 'axstrad_content']
Missing Soft Deletes
Content and add deletedAt field manually.$this->getDoctrine()->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
var_dump($content->toArray()) for debugging entity structure.Custom Fields
Add dynamic fields via addField() in entity constructors:
public function __construct()
{
$this->addField('metaDescription', 'string');
}
Content Events
Extend ContentEvents for custom logic:
class MyContentListener
{
public function onContentPublish(ContentEvent $event)
{
// Logic on publish
}
}
Serializer Groups
Override normalization groups in config.yml:
axstrad_content:
serializer:
groups: [default, 'api']
How can I help you explore Laravel packages today?