这个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'))
);
但在这种情况下,我们需要将整个国家/地区列表添加到路线中。即印度、中国、巴基斯坦、美国等。
然后将添加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 http://framework.zend.com/manual/1.11/en/zend.controller.router.html#zend.controller.router.routes.regex我们应该有类似的东西example.com/en/country/spain/barcelona/barcelona/taxis
并且所有动作都集中在一个动作上。由于视图完全不同,因此变得肮脏。可能是我可以使用的部分。但我想知道是否还有其他好的解决方案来解决这个问题。这是一个遗留项目,所以我对其有限制,#ZF 版本是 1.6。
有一个类似的例子
http://www.travelportal.info/ http://www.travelportal.info/http://www.travelportal.info/asiahttp://www.travelportal.info/asia/india http://www.travelportal.info/asia/indiahttp://www.travelportal.info/asia/india/business-currency-economy
你觉得怎么样,他们这样做了,会不会增加至少亚洲、欧洲之类的航线?
我能够让它像
example.com/en/spain
指向CountryController
indexAction
example.com/en/spain/barcelona
指向CountryController
provinceAction
example.com/en/spain/barcelona/barcelona
指向CountryController
cityAction
example.com/en/spain/barcelona/barcelona/taxis
指向CountryController
productAction
但我需要添加 4 条路由,这样手动添加路由会变得很困难。
欢迎提出建议和批评,以便做得更好。