bsdrazor/ckfinder-symfony-bundle
Install the Bundle
composer require bsdrazor/ckfinder-symfony-bundle
Ensure your config/bundles.php includes CKSource\CKFinderBundle\CKSourceCKFinderBundle::class.
Download CKFinder Run the CLI command to fetch the distribution:
php bin/console ckfinder:download
Verify the files are in vendor/cksource/ckfinder-symfony-bundle/Resources/public/.
Enable Routing
Create config/routes/ckfinder.yaml:
ckfinder_connector:
resource: "@CKSourceCKFinderBundle/Resources/config/routing.yml"
prefix: /ckfinder
Clear cache:
php bin/console cache:clear
Configure Storage
Create a writable directory (e.g., public/userfiles) and update config/packages/ckfinder.yaml:
ckfinder:
storage:
directory: "%kernel.project_dir%/public/userfiles"
First Use Case Integrate with CKEditor in a Twig template:
{{ ckeditor_widget('article_content', {
'filebrowserImageBrowseUrl': '/ckfinder/browser/browse.php?type=Images',
'filebrowserImageUploadUrl': '/ckfinder/core/connector/php/upload.php?type=Images',
'filebrowserBrowseUrl': '/ckfinder/browser/browse.php?type=Files',
'filebrowserUploadUrl': '/ckfinder/core/connector/php/upload.php?type=Files'
}) }}
File Management
/ckfinder/core/connector/php/upload.php) for handling file uploads from CKEditor./ckfinder/browser/browse.php) for file selection dialogs.@IsGranted("ROLE_USER")).Custom Storage Backends
Override the default directory storage by implementing CKSource\CKFinderBundle\Storage\StorageInterface and configure it in config/packages/ckfinder.yaml:
ckfinder:
storage:
class: App\Service\CustomStorageService
Asset Optimization
php bin/console assets:install public
config/packages/ckfinder.yaml for development:
ckfinder:
debug: true
Twig Integration Embed CKFinder in forms or templates:
{% set ckfinderConfig = {
'uploadUrl': path('ckfinder_upload', {'type': 'Files'}),
'browseUrl': path('ckfinder_browse', {'type': 'Files'})
} %}
{{ ckeditor_widget('field_name', ckfinderConfig) }}
API-Driven Uploads For non-CKEditor uploads, use the connector directly via HTTP requests:
// Example: Upload via fetch API
const formData = new FormData();
formData.append('upload', file);
fetch('/ckfinder/core/connector/php/upload.php?type=Files', {
method: 'POST',
body: formData
});
License Compliance
ckfinder:download to fetch the latest version.userfiles directory is writable by the web server user (e.g., www-data or nginx).Routing Conflicts
prefix in ckfinder.yaml doesn’t clash with existing routes. Test with:
php bin/console debug:router | grep ckfinder
CORS Issues
# config/packages/nelmio_cors.yaml
nelmio_cors:
paths:
'^/ckfinder/':
allow_origin: ['*']
allow_methods: ['GET', 'POST']
Debugging Uploads
/_profiler) for failed uploads. Common causes:
enctype="multipart/form-data" in forms.type parameter (e.g., Files vs. Images).upload_max_filesize in php.ini if needed).Symfony 6+ Quirks
{{ ckeditor_script() }}
{{ ckfinder_script() }}
Environment-Specific Config
Override settings per environment (e.g., config/packages/ckfinder_dev.yaml):
ckfinder:
debug: true
storage:
directory: "%kernel.project_dir%/public/userfiles_dev"
Custom Connector Logic
Extend the connector by overriding the CKSourceCKFinderBundle\Connector\Connector class and update the service in config/services.yaml:
services:
CKSourceCKFinderBundle\Connector\Connector:
class: App\Connector\CustomConnector
File Type Restrictions
Restrict uploads by file type in config/packages/ckfinder.yaml:
ckfinder:
allowed_file_types:
Images: ['jpg', 'png', 'gif']
Files: ['pdf', 'docx', 'txt']
Logging Enable debug logging to track connector activity:
ckfinder:
debug: true
Check logs at var/log/dev.log.
Docker Setup
For Dockerized environments, ensure volumes are mounted for userfiles:
# docker-compose.yml
services:
app:
volumes:
- ./public/userfiles:/var/www/public/userfiles
How can I help you explore Laravel packages today?