Reputation: 105
I have a problem in my controller when I want to get a sevice that I create, everything work well when I'm in localhost, but when I put the website in my server I get the problem.
Here is the line that make the error in my controller:
$myService = $this->get('Acme_test.service');
The services.yml
:
services:
Acme_test.service:
class: Acme\testBundle\Services\Testservice
arguments: [%folder%, @service_container]
And the error:
ClassNotFoundException: Attempted to load class "Testservice" from namespace "Acme\TestBundle\Services" in /home/www/acme/app/cache/dev/appDevDebugProjectContainer.php line 736. Do you need to "use" it from another namespace?
I tried to clear the cache, still having the same error !!
Upvotes: 0
Views: 1277
Reputation: 12306
You need to set nested your service to the services
node in the services.yml
file like:
services:
acme_test.service:
class: Acme\TestBundle\Service\TestService
arguments: [%folder%, @service_container]
And I think better write service name in lowercase. And then get service in controller like:
$myService = $this->get('acme_test.service');
NOTE: I think that you meant TestBundle
and TestService
names in camelCase
NOTE2: And commonly services dir name is Service
, so check your namespace, it need to be Acme\TestBundle\Service
, class name need to be TestService
and file Acme\TestBundle\Service\TestService.php
must exists.
NOTE3: After all recommendations and modifications manually clear cache dir.
Upvotes: 2