此网址结构是为SEO优化提出的。所以建议另一种结构将不起作用。提出的结构Zend框架中的国家,省份,城市,产品路由
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'))
);
但是,在这种情况下,我们需要国家的整个列表添加到路由。即印度,中国,巴基斯坦,美国等。
然后将增加country_province
$router = $ctrl->getRouter();
$router->addRoute(
'country_spain_barcelona',
new Zend_Controller_Router_Route('spain',
array('controller' => 'country',
'action' => 'province'))
);
因此,如果我们有50个省份将是可怕的添加国家乘以省份的国家数的计数,并转移到城市的时候,这将成为多条航线和产品。
你可能会说添加类似
$router = $ctrl->getRouter();
$router->addRoute(
'country',
new Zend_Controller_Router_Route('country/:country/:province/:city/:product',
array('controller' => 'country',
'action' => 'index'))
);
但在这种情况下,它就像我们将指向同样的动作,但由于请求的看法改变,这将成为一种脂肪控制器。
Zend_Controller_Router_Route_Regex的问题是我们应该有类似 example.com/en/country/spain/barcelona/barcelona/taxis
以及所有移动到一个单一的行动。由于观点完全不同,它变得肮脏。可能会像我可以使用的部分。但我想知道是否有另一个解决这个问题的好方法。这是一个遗留项目,所以我对它有限制,#ZF版本是1.6。
有类似
http://www.travelportal.info/ http://www.travelportal.info/asia http://www.travelportal.info/asia/india HTTP为例东西://www.travelportal。info/asia/india/business-currency-economy
你觉得呢,他们已经这样做了,他们是否至少为亚洲这样的欧洲添加了路线?
我能够使它工作像指着CountryController
indexAction
example.com/en/spain/barcelona
example.com/en/spain
指着CountryController
provinceAction
example.com/en/spain/barcelona/barcelona
指着CountryController
cityAction
example.com/en/spain/barcelona/barcelona/taxis
指着CountryController
productAction
但是,我需要添加4条路线,这将变得很难手动添加这样的路线。
欢迎提出建议和批评,让它更好。
+1右上。标准路线 - 以正确的顺序! - 应该处理它。 ;-) – 2012-02-03 12:41:08
感谢您的提示,我不确定为什么我没有想到这一点,我会尝试在星期一上述解决方案,并报告回来。但是一个简单而快速的问题是,如果我已经有一个使用'$ router-> addRoute的路由会发生什么( 'differentroute', new Zend_Controller_Router_Route(':lang /:something',array( 'controller'=>'某些控制器', 'action'=>'index' )) );'需要哪条路线? – 2012-02-04 16:59:20
对不起,这条路线的问题是所有的路线将转移到国家的控制器。有更多的路线:(。 – 2012-02-06 04:44:13