我是Zend的初学者.我may_terminate在模块路由配置中看到过.我不明白它的用途.根据ZF2官方文档,
the option “may_terminate” hints to the router that no other
segments will follow it.
Run Code Online (Sandbox Code Playgroud)
我仍然没有得到的含义no other segments will follow it.这是什么it?有人可以用小例解释吗?
当前状态:
问题: - 需要知道从请求中分派/使用的路由名称.
例如:1. http://www.mycompany.com/en/trainers/ 预期的返回值:WWW的语言教练
我想知道如何在ZF2中翻译一个有参数的网址.
例如:
/{:language_link-schools-:city_link}
Run Code Online (Sandbox Code Playgroud)
我不这样做的原因:
/:language_link-{schools}-:city_link
Run Code Online (Sandbox Code Playgroud)
是因为在某些语言中,例如西班牙语,单词的顺序会发生变化.
我正在使用PhpArray,当我翻译它时,参数不会被替换,因此url呈现为(例如西班牙语):
/:language_link-escuela-:city_link
Run Code Online (Sandbox Code Playgroud)
而不是预期的行为:
/ingles-escuela-miami
Run Code Online (Sandbox Code Playgroud)
编辑:
参数是
:language_link和:city_link
因此,我们的想法是,在一种语言中,呈现的URL可能是:
/:language_link-schools-:city_link
Run Code Online (Sandbox Code Playgroud)
用另一种语言可能是:
/:language_link-:city_link-school
Run Code Online (Sandbox Code Playgroud)
与您在翻译语句时执行的操作类似:
sprintf($this->translate('My name is %s'), $name) ;
Run Code Online (Sandbox Code Playgroud) 如何使路由自动适用于ZF1结构中的所有内容?
模块/控制器/动作/ par1Name/par1Val/par2Name/par2Val /
我阅读了有关路由的信息,但是我看到它的方式,我必须手动添加所有操作,并且我看到可选参数的问题...
这个url结构被提议用于SEO优化.因此建议另一种结构不起作用.建议的结构是
example.com/<language>/<country>/<province>/<city>/<product>
example.com/en/spain我想指出CountryController indexAction,由于每个人的观点不同,有时候也认为布局也有变化.
显示关于国家西班牙的英语内容.对于请求example.com/en/india应该用英语显示印度,并example.com/es/spain应显示西班牙国家的西班牙语页面.
example.com/en/spain/barcelona 指着 CountryController provinceAction
西班牙巴塞罗那省英语语言内容页面.
example.com/en/spain/barcelona/barcelona 指着 CountryController cityAction
西班牙巴塞罗那省巴塞罗那市的英文内容页面.
example.com/en/spain/barcelona/barcelona/taxis 指着 CountryController productAction
该产品的内容页面在巴塞罗那市,西班牙国家西班牙语的英语.
是的,我们可以添加一条路线
$router = $ctrl->getRouter();
$router->addRoute(
'country_spain',
new Zend_Controller_Router_Route('spain',
array('controller' => 'country',
'action' => 'index'))
);
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我们需要将整个国家列表添加到路线中.即印度,中国,巴基斯坦,联合国等.
然后将添加country_province
$router = $ctrl->getRouter();
$router->addRoute(
'country_spain_barcelona',
new Zend_Controller_Router_Route('spain',
array('controller' => 'country',
'action' => 'province'))
);
Run Code Online (Sandbox Code Playgroud)
因此,如果我们有50个省,那么增加国家数量乘以各国的省份数将是可怕的,这将成为转移到城市和产品时的更多路线.
你可以说添加类似的东西
$router = $ctrl->getRouter();
$router->addRoute(
'country',
new Zend_Controller_Router_Route('country/:country/:province/:city/:product',
array('controller' => 'country',
'action' => 'index'))
);
Run Code Online (Sandbox Code Playgroud)
但在这种情况下它就像我们将指向相同的动作,但随着请求的视图改变,这将成为一个胖控制器.
Zend_Controller_Router_Route_Regex的问题是我们应该有类似的东西
example.com/en/country/spain/barcelona/barcelona/taxis以及所有移动到单个动作.由于视图完全不同,它变得很脏.可能是我可以使用的偏见.但我想知道是否有另一个好的解决方案可以解决这个问题.这是一个遗留项目,所以我对它有限制,#ZF版本是1.6.
有一个类似的例子 …
我试图为2个不同的模块使用相同的路由名称,是否可能?
模块用户:
/*Module.config.php*/
'dashboard' => array(
'type' => 'segment',
'options' => array(
'route' => '/dashboard',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Users\Controller\Users',
'action' => 'dashboard',
),
),
),
Run Code Online (Sandbox Code Playgroud)
模块管理员:
/*Module.config.php*/
'dashboard' => array(
'type' => 'segment',
'options' => array(
'route' => '/dashboard',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Admin\Controller\Admin',
'action' => 'dashboard',
),
),
),
Run Code Online (Sandbox Code Playgroud)
虽然我正在为仪表板创建2个不同的模块,但我只加载任何一个动作.
我怎样才能做到这一点?