如何使用 Symfony 中的 getRoute 获取对象及其翻译?
我有几个带翻译的模型。当我加载
$this->tour = $this->getRoute()->getObject();
示例时,它会获取游览对象。但是,它不会加入到tour_translation表中;所以当我尝试获得它的标题后; symfony 进行另一个 sql 查询。
我如何覆盖某些内容,因此在 Tour 模型中,当我请求该对象时,它会返回该对象及其在当前文化中的翻译。
我一直在查看 sfObjectRoute 类< /a> 看看我是否可以覆盖任何方法,但我现在不确定
我知道我可以执行以下操作,但我更喜欢第一个选项,因为它更透明和优雅:
$this->tour = Tour::getTour($request->getParameter('id'), $lang);
谢谢!
I have several models with translations. When I load
$this->tour = $this->getRoute()->getObject();
por example, it gets me the Tour Object. However, it doesn't join to the tour_translation table; so when after i try to get it's title; symfony makes another sql query.
How I can override something, so in the Tour model when I ask for the object, it returns me the object with its translation in the current culture.
I've been looking at the sfObjectRoute class to see if I can override any method, but I'm not sure right now
I know I can do the following, but I prefer the first option as it's more transparent and elegant:
$this->tour = Tour::getTour($request->getParameter('id'), $lang);
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在路由定义中指定通过
method
选项检索对象时使用什么方法:(为了简洁起见,跳过了
params
部分)请注意,该方法不会直接接收 id 作为参数,但将参数数组传递给路由,因此您可以编写如下方法:
最后注意:此选项仅在您使用 sfDoctrineRoute 时可用 或
sfPropelRoute
:-)You need to specify in your route definition what method to use when retrieving the object through the
method
option:(
params
section skipped for brevity sake)Be aware that the method will not receive the
id
directly as a parameter but an array of parameters passed to the route, thus you would write a method like that:Final note: this option is only available if you use either a
sfDoctrineRoute
or asfPropelRoute
:-)