How to call a service
We have called a service in our project before. To know the answer, open mava/src/AppBundle/Controller/DashboardController.php
and note two things:
<?php namespace AppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DashboardController extends Controller { public function indexAction() { $uId = $this->getUser()->getId(); $util = $this->get('mava_util'); //... } }
First, this class extends Symfony's Controller
class. Secondly, spot the get(mava_util)
method at line 9. This method is in charge of calling services and is defined in the Controller.php
class as follows:
/** * Gets a container service by its id. * @param string $id The service id * @return object The service */ public function get($id) { //... return $this->container->get($id); }
In this example, it calls the mava_util
service and benefits from its methods. Moving the query...