craue / CraueConfigBundle

Database-stored settings made available via a service for your Symfony project.
MIT License
173 stars 35 forks source link

Service "craue_config" not found #49

Closed antoine1003 closed 3 years ago

antoine1003 commented 5 years ago

Hi, I am trying to use this bundle but after following the step for the instalation when I want to retrieve a setting, an error is thrown at this line : $this->get('craue_config')->get('can_user_participate');.

The full error I get :

Service "craue_config" not found: even though it exists in the app's container, the container inside "App\Controller\DefaultController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.

I am using Symfony 4.2

Thanks, A.

karoman0584 commented 5 years ago

I have the same error.

karoman0584 commented 5 years ago

I found the solution, I am working with Symfony 4.2 here:

1 - In services.yaml put: Craue\ConfigBundle\Util\Config: '@craue_config_default' at the same level than _defaults

2 - In the the class where you will use it, something like this: use Craue\ConfigBundle\Util\Config; . . private $setting;

public function __construct(Config $setting) { $this->setting = $setting; }

then in methods...

$this->setting->get('name-of-a-setting');

That's all.

craue commented 4 years ago

Let me know if #57 helps and makes things clear enough, or if it's even too detailed that way.

With this PR, you can at least remove the entry from your services.yaml again as the bundle will define this alias.