KEIII KEIII - 2 months ago 20
Twig Question

How to insert a Controller in Twig with “render” in Silex

Should it work in Silex with symfony/twig-bridge ?

{{ render(controller('MyController')) }}


Now I have message like this:


Twig_Error_Syntax: The function "controller" does not exist in "...

Answer

I've found this working:

{{ render(controller('services.controller:action', {[params]}) }}

And you can define the controller as a service:

$app['services.controller'] = function() use ($dependecy1, .., $dependencyN){
    return new \\PathToYourControllerClass($dependecy1, .., $dependencyN);
}