works with plain silex-php
- Register Controllers as a Service with container, __construct and method injection
- register their actions over a static method within the controller
- php >=5.3
- silex/silex ~1.0
The ServiceControllerServiceProvider from silex itself is needed!
$app->register(new ServiceControllerServiceProvider());
$app->register(new SaxulumControllerProvider());
The example controllers ContainerExampleController and ServiceExampleController they implement ControllerRouteInterface
public static function addRoutes(Application $app, $serviceId)
{
$app
->get('/container', $serviceId . ':indexAction')
->bind('container_index')
;
}
$app['controller.map']
->addController()
->setNamespace('Saxulum\SaxulumControllerProvider\Controller\ContainerExampleController')
->setServiceId('saxulum.saxulumcontrollerprovider.controller.containerinjectcontroller')
->setInjectContainer(true)
->end()
->addController()
->setNamespace('Saxulum\SaxulumControllerProvider\Controller\ServiceExampleController')
->setServiceId('saxulum.saxulumcontrollerprovider.controller.serviceController')
->setInjectionKeys(array('test.data'))
->addMethod()
->setName('setTestData1')
->setInjectionKeys(array('test.data'))
->end()
->addMethod()
->setName('setTestData2')
->setInjectionKeys(array('test.data'))
->end()
->end()
;