Call to undefined method get()
Kue2 opened this issue · 3 comments
Hi all,
I'm new to Symfony and NelmioSolarium.
I have followed the steps of Installation Guide (added NelmioSolariumBundle to composer, updated composer, added NelmioSolariumBundle to AppKernel.php).
Then I have added these lines to app/config/config.yml:
nelmio_solarium: ~
nelmio_solarium:
endpoints:
default:
host: localhost
port: 8983
path: /solr
core: active
timeout: 5
clients:
default:
endpoints: [default]
But I get the error "call to undefined method get()" on this line:
$client = $this->get('solarium.client');
I think I'm doing something wrong with my configuration.
Can you help me?
Thank you in advance!
$this->get() only works in symfony controllers extending the base controller class, since it relies on the shortcut method to get a service by name out of the dependency injection container. If you are getting this error I am assuming you are calling this in some non-controller class. In this case you typically would need to create your class via a service in the DIC, and then inject the solarium.client service into it. I hope this makes sense, I am not sure how much symfony knowledge you have already.
Oh thank you, I was going crazy, and simply I forgot to extend the class! Now everything works.
Thank you for your help and thank you for your bundle Jordi!
OK all is well then ;)