I am trying to use Silex and I have a little problem, or I can say more inconvenience ...
I am trying to load 2 routes from 2 separate yaml files, but for some reason setting ( $app->mount(...)) does not work with closing.
Here is the code:
$loader->load('core.yml');
$loader->load('api.yml');
function bla($app, $container, $key) {
$myApp = $app['controllers_factory'];
foreach ($container->getExtensionConfig('routes')[$key] as $name => $route) {
$controller = $myApp->match($route['pattern'], $route['controller']);
$controller->method($route['requirements']['_method']);
$controller->bind($name);
}
return $myApp;
}
$app->mount('/core', bla($app, $container, 0));
$app->mount('/api', bla($app, $container, 1));
It works.
What does not work if I do the same with closing, for example:
$app->mount('/core', function ($app, $container, $key) {
return $app['controllers_factory'];
});
Gives the following error:
LogicException: The "mount" method takes either a ControllerCollection or a ControllerProviderInterface instance.
But
var_dump($app['controllers_factory']);
splashes out an object of type Silex\ControllerCollection.
I am clearly missing something.
Thank you for your help.
source
share