Php 始终在zend framework 2(ZF2)的url路由中包含当前语言环境
如何包括当前区域设置,如en、tr、。。。在url中。你可以在symfony或Joomla中看到类似的情况。Php 始终在zend framework 2(ZF2)的url路由中包含当前语言环境,php,zend-framework,zend-framework2,Php,Zend Framework,Zend Framework2,如何包括当前区域设置,如en、tr、。。。在url中。你可以在symfony或Joomla中看到类似的情况。 当使用enter to this url时:这将自动转换为我希望在url中包含当前语言环境并识别它并更改网站语言环境。在Module.php文件中: public function onBootstrap(MvcEvent $e) { $em = StaticEventManager::getInstance(); $em->atta
当使用enter to this url时:这将自动转换为我希望在url中包含当前语言环境并识别它并更改网站语言环境。在Module.php文件中:
public function onBootstrap(MvcEvent $e)
{
$em = StaticEventManager::getInstance();
$em->attach('Zend\Mvc\Application', MvcEvent::EVENT_ROUTE, array($this, 'onRoute'),
}
public function onRoute(MvcEvent $e)
{
$routeLang = $e->getRouteMatch()->getParam('lang', false);
if(!$routeLang)
$e->getRouter()->setDefaultParam('lang', \Locale::getDefault());
}
以及您的主要路线配置:
'app' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:lang]',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
'constraints' => array(
'lang' => '[a-z]{0,2}',
),
),
),
所有其他路线都应该是此路线的子路线