0

I am storing a string in database that I want to access from various places in my application. I figure out that the best solution will be create a function that is taking that string from database and register it as a service.

Function:

public function shopUrlAction()
{ 
  return new Response($this->getDoctrine()->getRepository('AppBundle:Settings')->find(1)->getName());
}

service.yml

services:
  app.default_controller:
    class: AppBundle\Controller\DefaultController

output in other controller:

$return['base_url'] = $this->forward('app.default_controller:shopUrlAction');

Unfortunately I am constantly getting

CRITICAL - Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "You have requested a non-existent service "app.default_controller"." at /app/bootstrap.php.cache line 2099 Context: {"exception":"Object(Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException)"}

I've cleared cache.

6
  • Why are you using $this->forward();? You should do $this->get('app.default_controller')->shopUrlAction(); instead. Commented Jun 8, 2015 at 10:02
  • Sorry that was me trying weird solutions. Using $this->get still outputing You have requested a non-existent service "app.default_controller" Commented Jun 8, 2015 at 10:04
  • 1
    is your file service.yml is well registered in your DependencyInjection extension file ? Commented Jun 8, 2015 at 10:07
  • Also, are you sure that AppBundle is in the root of the src directory? Commented Jun 8, 2015 at 10:08
  • Why don't you create a service class that both/any of your controllers can use? Commented Jun 8, 2015 at 10:26

1 Answer 1

1

As I see from your question you have service.yml instead of services.yml (in plural form).

You should include your service.yml in main config.yml in imports section or use standard path to it (AppBundle/Resources/config/services.yml)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.