Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 - can't clear cache - You cannot create a service ("request") of an inactive scope ("request")

Tags:

symfony

whenever I try to clear the cache on the console I get the following error:

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

Has anyone experienced this before? Thanks.

Edit: Sample of code:

//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 Not sure which file you are looking for...

like image 745
greg Avatar asked Jul 10 '12 00:07

greg


2 Answers

For example to manually create scope "request" in CLI you may overload the initializeContainer kernel method in AppKernel class, simply by doing:

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');
        }
    }
}
like image 76
Максим Шатов Avatar answered Nov 05 '22 13:11

Максим Шатов


Fixed this problem by removing the request object in the constructor. As the CLI is headless there is no 'request' object unless it's manually created.

like image 42
greg Avatar answered Nov 05 '22 13:11

greg