I'd like to display new notifications on every page of my symfony 2 webapplication. I was advised to use a Twig Extension for this. I've created a function getFriendRequests in that extension, but I don't know if it's good practice to get data through my custom repository in the twig extension: Right now it's giving me the error, that it can't find the getDoctrine method.
<?php
namespace Tennisconnect\DashboardBundle\Extension;
class NotificationTwigExtension extends \Twig_Extension
{
    public function getFriendRequests($user)
    {
        $users = $this->getDoctrine()
            ->getRepository('TennisconnectUserBundle:User')
            ->getFriendRequests();
        return count($users);
    }
    public function getName()
    {
        return 'notification';
    }
    public function getFunctions()
    {
        return array(
            'getFriendRequests' => new \Twig_Function_Method($this, 'getFriendRequests'));
    }
}