【发布时间】:2011-12-09 19:10:20
【问题描述】:
我想在我的 symfony 2 web 应用程序的每个页面上显示新的通知。 有人建议我为此使用 Twig Extension。我在该扩展中创建了一个函数 getFriendRequests,但我不知道通过我在 twig 扩展中的自定义存储库获取数据是否是一种好习惯:现在它给了我错误,它找不到 getDoctrine 方法.
<?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'));
}
}
【问题讨论】:
-
您是否考虑过使用专门为通知设计的捆绑包,例如merkNotificationBundle?
标签: symfony doctrine-orm twig