【发布时间】:2019-08-06 02:48:50
【问题描述】:
我是学习 symfony4 的新手。我在树枝扩展中使用该学说时遇到问题。如何在树枝扩展中使用教义查询。
请帮我如何配置此代码的服务
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
class AppExtension extends AbstractExtension
{
public function getFilters(): array
{
return [
// If your filter generates SAFE HTML, you should add a third
// parameter: ['is_safe' => ['html']]
// Reference: https://twig.symfony.com/doc/2.x/advanced.html#automatic-escaping
new TwigFilter('filter_name', [$this, 'doSomething']),
];
}
public function getFunctions(): array
{
return [
new TwigFunction('followed', [$this, 'doSomething']),
];
}
public function doSomething($id, $admin)
{
// ...
$follower = $this->getDoctrine()->getRepository(Follower::class)->findAll();
foreach( $follower as $value ){
if($value['user']==$admin && $value['followed_user']==$id) return false;
}
return true;
}
}
这是我的树枝功能代码
{% if followed(users.id, app.user.id) %}
运行页面时出现错误 试图调用“App\Twig\AppExtension”类的名为“getDoctrine”的未定义方法。
请帮我提供解决方案
【问题讨论】:
标签: php doctrine-orm doctrine symfony4