@Rabbis @Federico , BeforeControllerExecuteListener, . FilterControllerEvent, , Silex, .
public function onKernelController(FilterControllerEvent $event)
{
$collection = $event->getController();
$controller = $collection[0];
if($controller instanceof BaseControllerAwareInterface){
$controller->initialize($this->app, $event->getRequest());
}
}
, :
$app['dispatcher']->addSubscriber(new BeforeControllerExecuteListener($app));
, . , :
public function listAction($customer)
{
$connection = $this->getApplication()['dbs']['db_orders'];
$orders= $connection->fetchAll($sqlQuery);
$results = array();
foreach($orders as $order){
$results[$order['id']] = $order['number'] . ' (' . $order['customer'] . ')';
}
return new JsonResponse($results);
}
If the current controller that is being called is distinguished by the BaseControllerAwareInterface interface, as I defined it, then I must enter this controller with instances of the application and the request. I leave the controllers to decide how they control the response of each action, as with my example above. I might need the JsonResponse Response object itself, even any other type of response, so it depends entirely on the controller to take care of this.
Then the routing remains the same as:
$app->match('/orders/list/{cusstomer}', 'Luyanda\Controller\OrdersController::listAction')
->bind('list-orders');
source
share