ekino / EkinoWordpressBundle

Integrate Symfony with WordPress and WordPress with Symfony
GNU General Public License v2.0
311 stars 79 forks source link

Any idea how to use one of the services in EventSubscriber action? #135

Open phtmgt opened 6 years ago

phtmgt commented 6 years ago

Trying to do this in Symfony 3.3 we always get "Attempted to call an undefined method named "get" of class "AppBundle\EventSubscriber\SitemapBlogPostsSubscriber""

The call in question is this: $postManager = $this->get('ekino.wordpress.manager.post');

We tried defining 'ekino.wordpress.manager.post' as an attribute for the service in services.yml, but no luck.

Any suggestions are highly appreciated.

Thanks.

wiejakp commented 6 years ago

You will only be able to access services through "$this->get()" if your SitemapBlogPostsSubscriber class inherits from ContainerAwareInterface. Instead of doing that, you could inject service ekino.wordpress.manager.post into your class.