KEIII KEIII - 1 year ago 283
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 Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download