eZ Community » Forums » eZ Publish 5 Platform » Display a Symfony controller in an...
expandshrink

Display a Symfony controller in an eZ4 module/view

Display a Symfony controller in an eZ4 module/view

Sunday 02 June 2013 7:08:48 pm - 4 replies

Hello all,

I heard during the ezunconf that it would be possible to display a Symfony Controller in a legacy module/view.

I tried but did not succeed. Do you have a clue or a snippet to do so ?

Thank you very much, it would save me a lot of time and can be usefull to do the transition between eZ4 and eZ5.

Bye

Sunday 02 June 2013 7:29:16 pm

Hi Paul,

actually, that's quite simple. First, you need to retrieve the Symfony Dependency Injection Container. This is explained in the documentation: https://confluence.ez.no/display/EZP51/Legacy+code+and+features#Legacycodeandfeatures-UsingeZPublish5andSymfonyfeaturesinLegacy

Then, with it, you'll be able to retrieve any Symfony service, so if you retrieve a controller, you can execute any method of it and you just have to fill the correct entry in the $Result variable like in any legacy module.

This gives something like:

<?php
 
$container = ezpKernel::instance()->getServiceContainer();
$controller = $container->get( 'service.id.of.the.controller' );
 
$Result['content'] = $controller->myMethodAction( $param1, $param2 );

Cheers

Sunday 02 June 2013 9:39:28 pm

Wow, I did not expect an answer on sunday. Thank you Damien. I will test this on tomorrow.

Sunday 02 June 2013 10:00:37 pm

Hi Paul

Damien is right. However, you'll need a bit more work as you need to declare your Symfony controller as a service (see Symfony documentation for that).

A more comprehensive example can be found in this gist : https://gist.github.com/lolautruche/5694727

Wednesday 04 September 2013 2:50:04 pm

mmm, I smell a new fetch function coming...

 

 

blunk.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from