Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
eZ Publish 5 - Legacy module with a Symfony controller
* AcmeTestBundle/Controller/AdminController.php
namespace Acme\TestBundle\Controller;
use eZ\Bundle\EzPublishCoreBundle\Controller;
* Here is your Symfony controller, defined as a service (see service definition below)
class AdminController extends Controller
public function myAdminAction( $myParam = null )
return $this->render(
'some_var' => $myParam
{# AcmeTestBundle/Resources/views/my_admin_action.html.twig #}
<h1>We did it with a Symfony controller !</h1>
<h2>{{ some_var }}</h2>
# AcmeTestBundle/Resources/config/services.yml
my.admin.controller.class: Acme\TestBundle\Controller\AdminController
# Defining this controller as a service so it can be called from the container
# in the legacy module
class: %my.admin.controller.class%
# This setter is mandatory to be able to use all shorthand methods
- [setContainer, [@service_container]]
* ezpublish_legacy/extension/myextension/modules/mymodule/sftest.php
* Simple module test to use Symfony
* This is your legacy module view
$Module = $Params['Module'];
$Result = array();
$container = ezpKernel::instance()->getServiceContainer();
/** @var \Acme\TestBundle\Controller\AdminController $controller */
$controller = $container->get( 'my.admin.controller' );
$Result['content'] = $controller->myAdminAction( 'blabla' )->getContent();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment