我在 Resources/config/services.yml 中定义了一个服务:
services:
gSm.gate.terminal:
class: Stream\TerminalBundle\StreamTerminal
arguments: [ [], [%terminal_login%, %terminal_password%] ]
我尝试在我的控制器操作中访问:
public function displayAction() {
$terminal = $this->get('gSm.gate.terminal');
return $this->render('StreamTerminalBundle::display.html.twig');
}
服务器返回以下异常:500 You have requested a non-existent service "gsm.gate.terminal"
。该捆绑包已在 appKernel 中注册,该捆绑包使用 .yml 配置文件...我不知道还有什么可以使该服务可用...感谢您的帮助。
编辑:
我的扩展类代码是:
namespace Stream\TerminalBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class StreamTerminalExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}