Install via Composer:
composer require avoo/qcm-public-bundle "@dev-master"
Note: Use @dev-master as the package isn't officially released.
Register Bundles:
In AppKernel.php, add both QcmCoreBundle and QcmPublicBundle to the registerBundles() method:
new Qcm\Bundle\CoreBundle\QcmCoreBundle(),
new Qcm\Bundle\PublicBundle\QcmPublicBundle(),
Configure Routing:
Add the routing imports to app/config/routing.yml:
qcm_core:
prefix: /
resource: "@QcmCoreBundle/Resources/config/routing.yml"
qcm_public:
resource: "@QcmPublicBundle/Resources/config/routing.yml"
prefix: /
Import Configs:
In app/config/config.yml, import the core configs:
imports:
- { resource: @QcmCoreBundle/Resources/config/core.yml }
- { resource: @QcmPublicBundle/Resources/config/core.yml }
First Use Case:
Access the public QCM (Questionnaire, Course, Module) routes via /. The bundle provides public-facing endpoints for QCM content, likely including:
Public Content Exposure:
/quiz/{id}) to display public-facing QCM content.{% extends 'base.html.twig' %}
{% block body %}
{{ render(controller('QcmPublicBundle:Quiz:show', {'id': quizId})) }}
{% endblock %}
Dependency on QcmCoreBundle:
QcmCoreBundle for data models (e.g., Quiz, Question, Course).QcmCoreBundle if customization is needed.Configuration-Driven Behavior:
config.yml or parameters.# app/config/config.yml
parameters:
qcm_public.allowed_ips: ['192.168.1.1', '127.0.0.1']
Integration with Frontend:
fetch(`/api/quiz/${id}/public`, { headers: { 'Accept': 'application/json' } })
.then(response => response.json())
.then(data => renderQuiz(data));
Event-Driven Extensions:
qcm.core.quiz.submitted) to extend public behavior.// src/Acme/AppBundle/EventListener/QcmListener.php
class QcmListener
{
public function onQuizSubmitted(GetResponseForQuizSubmittedEvent $event)
{
// Log or notify admins
}
}
Register the listener in services.yml:
services:
acme.qcm_listener:
class: Acme\AppBundle\EventListener\QcmListener
tags:
- { name: kernel.event_listener, event: qcm.core.quiz.submitted, method: onQuizSubmitted }
Missing QcmCoreBundle:
QcmCoreBundle. Forgetting to register it will cause ClassNotFound errors.AppKernel.php and configs are imported.Route Conflicts:
prefix: / in routing may clash with existing routes. Use unique prefixes or route namespaces:
qcm_public:
resource: "@QcmPublicBundle/Resources/config/routing.yml"
prefix: /public/qcm # Avoid root conflicts
Deprecated Symfony2 Syntax:
AppKernel, YAML configs).symfony/symfony:2.8.*) for testing.Lack of Official Docs:
QcmCoreBundle for core concepts.Resources/config/ and Controller/ directories for usage patterns.Anonymous Access Risks:
// src/Qcm/PublicBundle/Controller/QuizController.php
public function showAction($id)
{
$quiz = $this->getDoctrine()->getRepository('QcmCoreBundle:Quiz')->find($id);
if (!$quiz->isPublic()) {
throw $this->createAccessDeniedException();
}
// ...
}
Enable Debug Mode:
%kernel.debug%: true) helps inspect routes, services, and events.Check Event Dispatching:
bin/console debug:event-dispatcher to verify if events (e.g., qcm.core.quiz.submitted) are fired.Inspect Twig Templates:
Resources/views/. Override them in your app:
# app/config/config.yml
twig:
paths:
'%kernel.root_dir%/../vendor/avoo/qcm-public-bundle/Resources/views': QcmPublicBundle
'%kernel.root_dir%/Resources/views': AcmeAppBundle
Custom Public Routes:
routing.yml:
# app/config/routing.yml
acme_qcm_public:
resource: "@AcmeAppBundle/Resources/config/routing/qcm.yml"
prefix: /custom/qcm
Override Controllers:
QuizController) in your bundle:
namespace Acme\AppBundle\Controller;
use Qcm\Bundle\PublicBundle\Controller\QuizController as BaseQuizController;
class QuizController extends BaseQuizController
{
public function showAction($id)
{
// Custom logic
return parent::showAction($id);
}
}
Update services.yml to replace the original service:
services:
acme.qcm_public.quiz_controller:
class: Acme\AppBundle\Controller\QuizController
parent: qcm_public.quiz_controller
tags:
- { name: controller.service_arguments }
Add Public API Endpoints:
FOSRestBundle or NelmioApiDocBundle to document and expose public QCM data as JSON:
# app/config/routing.yml
acme_qcm_api:
type: rest
resource: "@AcmeAppBundle/Controller/QcmApiController"
prefix: /api/qcm
How can I help you explore Laravel packages today?