symfony - Non-existent service "request_stack" -


i writing symfony 2.6 application , i've encountered problem when trying inject requeststack service. want able current request within service, i'm getting following exception:

servicenotfoundexception: service "host_service" has dependency on non-existent service "request_stack". 

my service code service looks this:

<?php  namespace mybundle\dependencyinjection;  use symfony\component\httpfoundation\requeststack;  class hostservice {     protected $request;      public function __construct(requeststack $requeststack)     {         $this->requeststack = $requeststack;     }      public function getsomething()     {         $request = $this->requeststack->getcurrentrequest();         // stuff request stack         // return     } } 

services.yml

i've created services.yml file this:

# mybundle/resources/config/services.yml services:     host_service:         class:        mybundle\dependencyinjection\hostservice         arguments: ["@request_stack"] 

extension

i have created extension bundle:

<?php  namespace mybundle\dependencyinjection;  use symfony\component\dependencyinjection\containerbuilder; use symfony\component\config\filelocator; use symfony\component\httpkernel\dependencyinjection\extension; use symfony\component\dependencyinjection\loader\yamlfileloader;  class myextension extends extension {     public function load(array $configs, containerbuilder $container)     {         $loader = new yamlfileloader(             $container,             new filelocator(__dir__.'/../resources/config')        );         $loader->load('services.yml');     } }  

controller

the way i'm using service this:

$hostservice = $this->get('host_service'); $something = $hostservice->getsomething(); 

also tried

i tried injecting using method this:

protected $request;  public function setrequest(requeststack $request) {     $this->request = request; } 

but did not work (same exception, , yeah changed service in services.yml).

the question

according this article on symfony.com, should not inject request service , use requeststack instead. i've been trying in same matter article doing it, still won't work.

am forgetting something? using services in wrong way altogether (this first service)? not seeing something? why service request_stack not exist? of all: why not working?

the information led solution

i using symfony 2.3, not symfony 2.6.

use php app/console container:debug or debug:container 2.6 check if service exists , , maybe using wrong version of symfony


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -