我正在使用过滤器localizedcurrency在多语言网站中设置价格格式。由于这是房屋价格,因此我不需要小数部分。
除了使用replace过滤器之外,我无法找到隐藏方法。我想知道是否有更好的方法,因为使用replace它将意味着我必须替换英语中的点和法语中的逗号等等。
我也不能使用某种形式的substr,因为美元符号可以在值之前或之后。
我尝试将int而不是float传递给过滤器,但是它默认为 .00
谢谢!
我有一个"类别"实体包含
/**
* @ORM\Column(type="string", length=255)
*/
protected $nameFr;
/**
* @ORM\Column(type="string", length=255)
*/
protected $nameEn;
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试在视图中显示本地化名称,我可以使用以下方式显示其中一个:
{{ categories.nameFr }} and {{ categories.nameEn }}
Run Code Online (Sandbox Code Playgroud)
所以我制作了一个方法,getName()所以我可以使用{{ categories.name }}
我只需要访问语言环境,所以我protected $locale使用setter和getter向实体添加了一个属性,并在调用视图之前设置了语言环境(顺便说一下,我使用@Template进行返回):
$locale = $this->getRequest()->getLocale();
$categories->setLocale($locale);
return array(
'categories' => $categories
);
Run Code Online (Sandbox Code Playgroud)
这是有效的,但现在我实现了一个分页包KnpLabs/KnpPaginatorBundle,它需要发送一个查询而不是实体:
$em = $this->getDoctrine()->getManager();
$categoriesQuery = $em->createQueryBuilder()
->select('category')
->from('OylexCategoryBundle:Category', 'category')
;
$locale = $this->getRequest()->getLocale();
$categoriesQuery->setLocale($locale);
$paginator = $this->get('knp_paginator');
$categoriesPagination = $paginator->paginate(
$categoriesQuery,
$this->get('request')->query->get('page', 1),
30
);
return array(
'categoriesPagination' => $categoriesPagination
);
Run Code Online (Sandbox Code Playgroud)
这失败并显示错误消息:FatalErrorException: Error: …