【发布时间】:2016-04-12 06:10:54
【问题描述】:
我正在用 symfony2 开发一个应用程序。我面临本地化问题。我想在学说生命周期的 postLoad 事件中设置,但可以找到一种方法来做到这一点。我正在使用路由方法来设置我的本地例如:
http://example.com/en/content
这是我的听众:
namespace MyApiBundle\Listener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
class LocaleListener
{
private $local;
public function __construct($local) {
$this->local = $local;
}
public function postLoad(LifecycleEventArgs $args)
{
$local= 'en'; // I need to get the local from here
$entity = $args->getEntity();
if(method_exists($entity, 'setLocale')) {
$entity->setLocale($local);
}
}
}
有什么快速的方法可以从这里获取本地信息吗?不能使用新的 Request(),因为它总是返回 en 我还有其他 3 种语言。感谢您的帮助
【问题讨论】:
标签: php symfony doctrine-orm