Symfony 2 - 无法清除缓存 - 您无法创建非活动范围的服务("请求")("请求")

gre*_*reg 19 symfony

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

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

有谁之前经历过这个吗?谢谢.

编辑:代码示例:

//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);
    }
}
Run Code Online (Sandbox Code Playgroud)

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

Мак*_*тов 44

例如,要在CLI中手动创建范围"请求",您可以在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');
        }
    }
}
Run Code Online (Sandbox Code Playgroud)