MyService
当然是一件愚蠢的事情,但我无法注册MyBundle
src/我/MyBundle/
$ ls -R src/Me/MyBundle/
DependencyInjection/
MeMyBundleExtension.php
Configuration.php
Resources/
config/
services.yml
Services/
MyService.php
MyBundle.php
src/Me/MyBundle/DependencyInjection/MeMyBundleExtension.php
namespace Me\MyBundle\DependencyInjection;
// standard stuff
class MeMyBundleExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
// standard stuff loading the yml file
}
}
src/Me/MyBundle/DependencyInjection/Configuration.php
namespace Me\MyBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_services');
return $treeBuilder;
}
}
src/Me/MyBundle/Resources/config/services.yml
services:
me.myservice:
class: Me\MyBundle\Services\MyService
src/Me/MyBundle/Services/MyService.php
namespace Me\MyBundle\Services;
class MyService
{
public function __construct()
{
die('test');
}
}
当我尝试从控制器实例化它时,我可以看到我的服务没有注册
$test = $this->get('me.myservice');
您请求了一个不存在的服务“me.myservice”
这里有什么问题吗?
$ php app/console container:debug | grep me.mybundle
没有匹配项