Symfony 2 - 无法清除缓存 - 您无法创建非事件范围 ("request")的服务 ("request")

标签 symfony

每当我尝试清除控制台上的缓存时,都会收到以下错误:

 [Symfony\Component\DependencyInjection\Exception\InactiveScopeException]   
  You cannot create a service ("request") of an inactive scope ("request").

有人以前经历过这种情况吗?谢谢。

编辑:代码示例:

//accessing request object
namespace Greg\TestBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;
use HvH\APIschemaBundle\Controller\Validation;
use HvH\APIschemaBundle\Controller\Helpers;

//FOSRestBundle
use FOS\RestBundle\View\View;

class TestController extends Controller
{
    public function testAction(Request $request) 
    {                       
        //get any query strings
        $query_strings = $request->query->all();
        return($query_strings);
    }
}

XML 不确定您要查找哪个文件...

最佳答案

例如,要在 CLI 中手动创建作用域“request”,您可以重载 AppKernel 类中的 initializeContainer 内核方法,只需执行以下操作:

class AppKernel extends Kernel {
    public function registerBundles() {
        // ...
    }

    public function registerContainerConfiguration(LoaderInterface $loader) {
        // ...
    }

    protected function initializeContainer() {
        parent::initializeContainer();
        if (PHP_SAPI == 'cli') {
            $this->getContainer()->enterScope('request');
            $this->getContainer()->set('request', new \Symfony\Component\HttpFoundation\Request(), 'request');
        }
    }
}

关于Symfony 2 - 无法清除缓存 - 您无法创建非事件范围 ("request")的服务 ("request"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11405202/

相关文章:

php - Symfony2 JSON 示例

php - 在 symfony 应用程序中首次登录时强制更改密码

php - 为什么 Doctrine getter 方法会为 ID 返回 null?

php - Symfony 3.4 在我的包中使用 View

symfony - Akeneo:从变体组获取属性

php - Symfony:在防火墙后路由的 SecurityContext 中找不到 token

php - Doctrine 不会在 Mysql 中保留具有 bool 值和 PDO::ATTR_EMULATE_PREPARES = false 的实体

php - 在 symfony 3.0 中将表单定义为服务

php - 将 kernel.root_dir 注入(inject) Symfony2 中的实体构造函数

symfony - Symfony 2 中的 2 级实体文件夹