问题描述
我正在为管理面板使用奏鸣曲管理包.我想通过查询在 configureListFields 中显示数据.我有表 userChoiceProduct 和字段:-
I am using sonata admin bundle for admin panel. I want to show data in configureListFields through query. I have table userChoiceProduct and fields :-
User_Id
Product_Id
当用户选择任何产品并提交表单时,这些字段会自动填写.但是这些字段与其他表没有关系.我想在 configureListFields 中显示用户电子邮件和产品名称基于 User_Id 和 Product_Id.
These fields automatically fill when user select any product and submit form. But these fields no relationship to other table.and I want to show User Email and Product Name in configureListFieldsbases on User_Id and Product_Id.
谢谢!
推荐答案
我解决了这个问题:-
在奏鸣曲管理员列表中:-
In Sonata Admin list :-
->add('User Email', null, array('template' => 'ABCAdminBundle:UserChoiceProduct:user.html.twig'))
->add('Product Name', null, array('template' => 'ABCAdminBundle:UserChoiceProduct:prodcut.html.twig'))
我提到了一个 twig 文件(user.html.twig),例如:
I mentioned one twig file (user.html.twig) for example :
<td>{{object.userId|getUserDetail()}}</td>
并在树枝扩展中创建 getUserDetail() :-
And create getUserDetail() in twig extension :-
class ABCExtension extends \Twig_Extension {
private $generator;
private $container;
public function __construct(UrlGeneratorInterface $generator, Container $container) {
$this->generator = $generator;
$this->container = $container;
}
public function getFilters() {
return array(
'getUserDetail' => new \Twig_Filter_Method($this, 'getUserDetail'),
);
}
public function getUserDetail($userId)
{
$em = $this->container->get('doctrine')->getManager();
$user = $em->getRepository('ABCUserBundle:User')->findOneBy(array('id' =>$userId));
if(empty($user)){
$userEmail = 'User does not Exist';
return $userEmail;
}else{
$userEmail = $user->getEmail();
return $userEmail;
}
}
}
然后所有的工作都成功完成了.
And then all work is done successfully.
这篇关于Sonata Admin configureListFields 通过查询显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!