I'm trying to create a menu for my page with ezpublish5. I followed this tutorial http://partialcontent.com/Code/working-with-ez-publish-5-subrequests. I'm pretty new to Symfony, but I have my own bundle there and running, at least it is using my own pagelayout.html.twig.
我正在尝试使用ezpublish5为我的页面创建一个菜单。我按照本教程http://partialcontent.com/Code/working-with-ez-publish-5-subrequests。我是Symfony的新手,但我有自己的捆绑并运行,至少它使用我自己的pagelayout.html.twig。
I understand, what routing does, but I as far as I'm concerned in order to create a menu I need something else, probably a service, so I can do this in my twig-template
我明白,路由的作用是什么,但就我创建一个菜单而言,我需要其他东西,可能是一个服务,所以我可以在我的树枝模板中做到这一点
{{ render( controller( "myMenuController:myFunction" ) ) }}
So I add this to my my\Bundle\Resources\config\services.yml
所以我把它添加到我的\ Bundle \ Resources \ config \ services.yml
parameters:
my_root.menucontroller.class: my\Bundle\Controller\MenuController
services:
my_root.controller:
class: %my_root.menucontroller.class%
arguments: [@ezpublish.view_manager]
calls:
- [setContainer, [@service_container] ]
myalias:
alias: my_root.controller
When I open it in the browser it says:
当我在浏览器中打开它时,它说:
You have requested a non-existent service "myalias".") in "{% extends "Bundle::pagelayout.html.twig" %}
I checked other repos of ezp5 installations on github, they have pretty much the same yml-setup. I also realized, that when I make syntax errors on purpose in my services.yml it (while leaving out the call to the controller in the template) it doesn't change anything. Also I realized, that when I do the same in my\Bundle\DependencyInjection\myBundleExtension.php (which is supposed to load my services.yml file) it doesn't happen anything either.
我在github上检查了ezp5安装的其他回购,他们有几乎相同的yml-setup。我也意识到,当我在services.yml中故意制造语法错误时(在模板中省略对控制器的调用)它不会改变任何东西。我也意识到,当我在我的\ Bundle \ DependencyInjection \ myBundleExtension.php(它应该加载我的services.yml文件)中做同样的事情时,它也不会发生任何事情。
So I'm getting the feeling something with bundle-setup is wrong, that somehow not everything is loaded correctly. But what could it be? Somewhere in the docu of symfony2 it says that the load-method in the Bundle\DependencyInjection\xyzExtension.php gets called automatically.
所以我感觉到bundle-setup的错误,不知道所有东西都没有正确加载。但它可能是什么?在symfony2的文档中的某处,它表示Bundle \ DependencyInjection \ xyzExtension.php中的load-method被自动调用。
Would anyone have an idea of what could possibly be wrong with my setup? I'm really running out of ideas. And for the ezpublish5 part.. is this really the best way to create a menu right now?
有人会知道我的设置可能出现什么问题吗?我真的没想到了。对于ezpublish5部分..这真的是现在创建菜单的最佳方式吗?
1 个解决方案
#1
0
It does seem like your services are not being loaded.
看起来您的服务似乎没有被加载。
Symfony relies on a naming convention to load xyzExtension.php. It's tripped me up a few times. You can stick a die statement in xyzExtension.load just to verify it is indeed being called.
Symfony依赖于命名约定来加载xyzExtension.php。它让我绊了几次。您可以在xyzExtension.load中粘贴一个die语句,以验证它是否确实被调用。
If it is not being called than you can either change the extension class name to meet the convention or do what I do and just override the convention in your bundle class.
如果没有调用它,你可以更改扩展类名称以满足约定或执行我的操作,并覆盖bundle类中的约定。
namespace Cerad\Bundle\GameV2Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Cerad\Bundle\GameV2Bundle\DependencyInjection\GameExtension;
class CeradGameV2Bundle extends Bundle
{
public function getContainerExtension()
{
return new GameExtension();
}
}
And of course xyzExtension should have something like:
当然xyzExtension应该有类似的东西:
namespace Cerad\Bundle\GameV2Bundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
class GameExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
public function getAlias() { return 'cerad_game_v2'; }
}
From the command line you can verify your service is getting picked up:
从命令行,您可以验证您的服务是否被提取:
app/console container:debug : grep my_root
#1
0
It does seem like your services are not being loaded.
看起来您的服务似乎没有被加载。
Symfony relies on a naming convention to load xyzExtension.php. It's tripped me up a few times. You can stick a die statement in xyzExtension.load just to verify it is indeed being called.
Symfony依赖于命名约定来加载xyzExtension.php。它让我绊了几次。您可以在xyzExtension.load中粘贴一个die语句,以验证它是否确实被调用。
If it is not being called than you can either change the extension class name to meet the convention or do what I do and just override the convention in your bundle class.
如果没有调用它,你可以更改扩展类名称以满足约定或执行我的操作,并覆盖bundle类中的约定。
namespace Cerad\Bundle\GameV2Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Cerad\Bundle\GameV2Bundle\DependencyInjection\GameExtension;
class CeradGameV2Bundle extends Bundle
{
public function getContainerExtension()
{
return new GameExtension();
}
}
And of course xyzExtension should have something like:
当然xyzExtension应该有类似的东西:
namespace Cerad\Bundle\GameV2Bundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
class GameExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
public function getAlias() { return 'cerad_game_v2'; }
}
From the command line you can verify your service is getting picked up:
从命令行,您可以验证您的服务是否被提取:
app/console container:debug : grep my_root