i read the post on injecting repository into a service under Symfony21. I am trying since two days to adapt my code and I turning around.
I need your help.
So what is the problem :
I am adapting the bundle "RatingStar" (http://www.tipocode.com/symfony-2/symfony2-star-rating-system/) in Symfony3 and MongoDB.
I want use my mongodb in place doctrine (mysql) and i am lost :(
There is a service :
starbar.twig_extension:
class: PortailBundle\Twig\StarBarExtension
arguments: [ "@doctrine", "@request_stack" ]
tags:
-
name: twig.extension
Note : i try to substitue "@doctrine" by factory... and so on but i have some errors in my class in the arguments list.
There is a class like this :
class StarBarExtension extends \Twig_Extension
{
protected $doctrine;
private $RequestStack;
public function __construct(RegistryInterface $doctrine, RequestStack $RequestStack)
{
$this->doctrine = $doctrine;
$this->requestStack = $RequestStack;
}
public function getFunctions() {
return array(
'starBar' => new \Twig_Function_Method($this, 'myStarBar'),
);
}
public function myStarBar($numStar, $mediaId, $starWidth) {
$cookies = $this->requestStack->getCurrentRequest()->cookies->get('LilmodLemaedNote'.$mediaId);
$nbrPixelsInDiv = $numStar * $starWidth; // Calculate the DIV width in pixel
**$query = $this->get('doctrine_mongodb')->getRepository('PortailBundle:Notes')->findOneBy(array('ARTICLE' =>$mediaId));**
I follow a lot of example but without success. I don't know what i do with the service and what i have to declare in the class to use my query.
Please try to help me.