Data collectors
Now, it's time to discover a way to create your own profile section. Adding this might be useful if you are developing your own bundle and you want to give other developers an easy way to debug your code. To add the profile section, you need to create a new data collector. Let's assume that we want to track information about how many tasks and tags we have in the database.
Add the following code:
<?php // src/AppBundle/Collector/TaskDataCollector namespace AppBundle\Collector; use Doctrine\ORM\EntityManager; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollector; class TaskDataCollector extends DataCollector { /** * @var EntityManager */ protected $em; public function __construct(EntityManager $em) { $this->em = $em; }
In the constructor, we will inject entity manager through our service container configuration:
public function...