Installation:
composer require ekyna/cms-bundle
Add to config/bundles.php:
Ekyna\CmsBundle\EkynaCmsBundle::class => ['all' => true],
Basic Setup:
app/config/routing.yml to attach SEO/content:
ekyna_cms:
resource: "@EkynaCmsBundle/Resources/config/routing.yml"
prefix: /
app/config/routing.yml (e.g., homepage):
homepage:
path: /
defaults: { _controller: AppController::homepageAction }
First Use Case:
ekyna_admin bundle (if installed) or manually via the ekyna_cms:page:create command:
php bin/console ekyna_cms:page:create homepage --title="Welcome" --content="<h1>Hello!</h1>"
/ with dynamic content rendered.Attaching SEO/Content to Routes:
ekyna_cms.page entity to link content to Symfony routes.use Ekyna\CmsBundle\Entity\Page;
public function homepageAction(Request $request, Page $page)
{
return $this->render('homepage.html.twig', [
'content' => $page->getContent(),
'meta_title' => $page->getMetaTitle(),
]);
}
{{ page.content|raw }} {# Render HTML content #}
Responsive Layouts (Bootstrap 3):
app/Resources/EkynaCmsBundle/views/layouts/ (e.g., default.html.twig).{% extends 'EkynaCmsBundle::layouts/default.html.twig' %}
{% block content %}{{ parent() }}{{ page.content|raw }}{% endblock %}
Child Routes (with AdminBundle):
ekyna/AdminBundle is installed)./blog (static) → /blog/post-1 (dynamic child).Command-Line Management:
php bin/console ekyna_cms:page:create blog --title="Blog" --content="..."
php bin/console ekyna_cms:page:update blog --content="Updated content"
Ekyna\CmsBundle\Form\Type\PageType for CMS content editing.Page entity to add custom fields (e.g., author, publishDate).ekyna_cms.page.pre_save to modify content before saving.
// src/EventListener/CmsListener.php
public function onPreSave(PreSaveEvent $event) {
$page = $event->getPage();
$page->setMetaDescription('Default description');
}
Register in services.yml:
services:
App\EventListener\CmsListener:
tags:
- { name: kernel.event_listener, event: ekyna_cms.page.pre_save }
Outdated Dependencies:
symfony/symfony:^2.7 in composer.json).Missing AdminBundle:
ekyna/AdminBundle. Without it, use the CLI or manually create Page entities via Doctrine.Twig Auto-escaping:
page.content is rendered with |raw, which bypasses Twig’s auto-escaping. Sanitize content if user-generated:
{{ page.content|striptags|raw }} {# Remove HTML tags #}
Route Overrides:
routing.yml must precede dynamic CMS routes to avoid conflicts. Example:
# app/config/routing.yml
_cms:
resource: "@EkynaCmsBundle/Resources/config/routing.yml"
prefix: /
homepage:
path: /
defaults: { _controller: AppController::homepageAction }
Database Migrations:
ekyna_cms_page). Ensure migrations are run:
php bin/console doctrine:migrations:execute
404 Errors:
Page entity is linked to the route via page.route (e.g., homepage).ekyna_cms.page.find_by_route in the database.Content Not Rendering:
php bin/console cache:clear
Bootstrap Conflicts:
app/Resources/EkynaCmsBundle/views/layouts/default.html.twig.Custom Fields:
Page entity:
// src/Entity/ExtendedPage.php
use Ekyna\CmsBundle\Entity\Page;
class ExtendedPage extends Page {
private $customField;
// Add getters/setters and Doctrine annotations.
}
EkynaCmsBundle/Form/Type/PageType.php.Custom Layouts:
EkynaCmsBundle::layouts/default.html.twig to app/Resources/EkynaCmsBundle/views/layouts/.Event System:
ekyna_cms.page.post_publish):
// src/Event/CustomEvent.php
class CustomEvent extends Event {
public function __construct(Page $page) { ... }
}
public function onPostPublish(PostPublishEvent $event) {
$this->eventDispatcher->dispatch(new CustomEvent($event->getPage()));
}
CLI Commands:
publish flag):
// src/Command/CustomCommand.php
class CustomCommand extends ContainerAwareCommand {
protected function configure() {
$this->setName('ekyna_cms:page:publish');
}
protected function execute(InputInterface $input, OutputInterface $output) {
// Logic to publish a page.
}
}
services.yml:
commands:
App\Command\CustomCommand:
tags: ['console.command']
How can I help you explore Laravel packages today?