Created
June 2, 2013 19:58
-
-
Save lolautruche/5694727 to your computer and use it in GitHub Desktop.
eZ Publish 5 - Legacy module with a Symfony controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
) | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# AcmeTestBundle/Resources/views/my_admin_action.html.twig #} | |
<h1>We did it with a Symfony controller !</h1> | |
<h2>{{ some_var }}</h2> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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