Skip to content

Instantly share code, notes, and snippets.

@lolautruche
Created June 2, 2013 19:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lolautruche/5694727 to your computer and use it in GitHub Desktop.
Save lolautruche/5694727 to your computer and use it in GitHub Desktop.
eZ Publish 5 - Legacy module with a Symfony controller
<?php
/**
* 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(
'AcmeTestBundle::my_admin_action.html.twig',
array(
'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
parameters:
my.admin.controller.class: Acme\TestBundle\Controller\AdminController
services:
# Defining this controller as a service so it can be called from the container
# in the legacy module
my.admin.controller:
class: %my.admin.controller.class%
calls:
# This setter is mandatory to be able to use all shorthand methods
- [setContainer, [@service_container]]
<?php
/**
* 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