Installation
composer require c33s/simple-gallery-bundle
Add to AppKernel.php:
new C33s\SimpleGalleryBundle\C33sSimpleGalleryBundle(),
Enable AdminGenerator
Ensure admingenerator is installed and configured. The bundle relies on it for CRUD operations.
First Use Case: Create a Gallery
fixtures.yml (as shown in the README).php app/console propel:data-load
/admin/gallery) to manage items.Display in Twig
Use the single_gallery('slug') helper in templates:
{% for item in single_gallery('background').galleryItems %}
<img src="{{ item.image|att_url('liip_imagine_filter_name') }}">
{% endfor %}
Directory-Based Uploads
ImagesLoadFromDirectory in fixtures to point to a local directory (e.g., app/propel/attachments/Gallery/background).Dynamic Sliders (e.g., Vegas)
backgrounds: [{% spaceless %}{% for item in single_gallery('hero').galleryItems %}
{ src: '{{ item.image|att_url('slider') }}', fade: 1000 }{% if not loop.last %},{% endif %}{% endfor %}{% endspaceless %}]
Integration with LiipImagine
att_url with Imagine filters:
{{ item.image|att_url('thumbnail') }}
liip/imagine-bundle is installed and filters are configured.Admin CRUD
Gallery and GalleryItem entities.app/Resources/views/admin/C33sSimpleGalleryBundle/Gallery) for additional fields.hero-images) for Twig templates.single_gallery() calls in controllers if galleries are static:
$gallery = $this->get('simple_gallery.manager')->getGalleryBySlug('hero');
Propel Dependency
Directory Permissions
ImagesLoadFromDirectory path is writable by the web server:
chmod -R 755 app/propel/attachments/
AdminGenerator Conflicts
# app/config/config.yml
admingenerator:
model_manager_name: propel
Image Paths in Production
app/propel/attachments) may break in shared hosting. Use kernel.root_dir or parameter('attachments_path'):
# fixtures.yml
ImagesLoadFromDirectory: "%attachments_path%/Gallery/background"
Missing Galleries? Check if fixtures loaded:
php app/console propel:data-dump --fixtures
Re-run propel:data-load if needed.
Broken Images? Verify:
ImageFilePath in fixtures points to an existing file.app/config/config.yml under liip_imagine).Twig Errors Ensure the gallery slug matches exactly (case-sensitive):
{# Correct: #}
{{ single_gallery('background').galleryItems }}
{# Incorrect (extra space): #}
{{ single_gallery('background ').galleryItems }} {# Fails #}
Custom Fields
Extend the GalleryItem model to add metadata (e.g., alt_text, caption):
# fixtures.yml
C33s\SimpleGalleryBundle\Model\GalleryItem:
item1:
gallery: [@background]
image: app/propel/attachments/Gallery/background/image1.jpg
alt_text: "Description of image1"
Update Twig templates to use the new field:
<img src="{{ item.image|att_url('thumbnail') }}" alt="{{ item.altText }}">
Override Admin Templates Copy default templates from:
vendor/c33s/simple-gallery-bundle/Resources/views/admin/
to:
app/Resources/views/admin/C33sSimpleGalleryBundle/
Customize forms/layouts (e.g., add file upload fields).
Event Listeners
Attach Propel listeners to GalleryItem for pre/post-save logic (e.g., auto-generate thumbnails):
// src/C33s/SimpleGalleryBundle/EventListener/GalleryListener.php
class GalleryListener
{
public function postSave(PostSaveEvent $event)
{
$item = $event->getObject();
if ($item instanceof GalleryItem) {
// Logic here
}
}
}
Register in services.yml:
services:
simple_gallery.listener:
class: C33s\SimpleGalleryBundle\EventListener\GalleryListener
tags:
- { name: propel.post_save_listener, model: GalleryItem }
Dynamic Slugs
Override the getSlug() method in the Gallery model to generate slugs dynamically (e.g., from title):
public function getSlug()
{
return strtolower(preg_replace('/[^a-z0-9]+/', '-', $this->getTitle()));
}
How can I help you explore Laravel packages today?