我已经成功安装了sncRedisBundle并在控制器中使用了它的predis元素,使用:
$this->container->get('snc_redis.default');
我想在扩展程序中执行相同操作:
class MyExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$redis = $container->get('snc_redis.default');
}
}
但我明白了:
The service definition "snc_redis.default" does not exist.
这是一个范围问题吗?如何从扩展程序中访问redis?
谢谢!
答案 0 :(得分:0)
services:
site:
class: Emlaktown\AppBundle\Site\Site
arguments: [%api_url%, "@request_stack", "@service_container"]
...
use Symfony\Component\DependencyInjection\Container;
...
public function __construct($apiUrl, RequestStack $requestStack, Container $container)
{
$this->client = new Client($apiUrl);
$this->redis = $container->get('snc_redis.cache');
$request = $requestStack->getCurrentRequest();
$this->client->setDefaultOption('Accept-Language', $request->getLocale());
}