Zend Framework 中的国家、省份、城市、产品路由
这个url结构是为了SEO优化而提出的。所以建议另一种结构是行不通的。建议的结构为
example.com/
example.com/en/spain
code> 我希望指向 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'))
);
,但在这种情况下,我们将指向相同的操作,但随着请求视图的变化,这将成为一个胖控制器。
有一个类似的示例
http://www.travelportal.info/ http://www.travelportal.info/asia http://www.travelportal.info/asia/india http://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 条路由,这样手动添加路由会变得很困难。
欢迎提出建议和批评,以便做得更好。
This url structure is proposed for SEO optimization. So suggesting another structure will not work. Structure proposed is
example.com/<language>/<country>/<province>/<city>/<product>
example.com/en/spain
I wish to point to CountryController
indexAction
, as view of each one is different, and sometimes think there is change in layout also.
Show the content in English language about the country Spain. And for a request example.com/en/india
should show about India in English language and example.com/es/spain
should show the spanish page for the country Spain.
example.com/en/spain/barcelona
Points to CountryController
provinceAction
Content Page for the Barcelona province of Spain in English Language .
example.com/en/spain/barcelona/barcelona
Points to CountryController
cityAction
Content Page for the Barcelona city in Barcelona province of country Spain in English Language .
example.com/en/spain/barcelona/barcelona/taxis
Points to CountryController
productAction
Content Page for the product in Barcelona city , Barcelona province of country Spain in English Language .
Yes we can add a route like
$router = $ctrl->getRouter();
$router->addRoute(
'country_spain',
new Zend_Controller_Router_Route('spain',
array('controller' => 'country',
'action' => 'index'))
);
But in this case we need to add the whole list of countries to the route. ie india , china , pakistan , unitedstates etc .
Then will be adding country_province
$router = $ctrl->getRouter();
$router->addRoute(
'country_spain_barcelona',
new Zend_Controller_Router_Route('spain',
array('controller' => 'country',
'action' => 'province'))
);
So if we have 50 province it will be horrible to add count of countries multiplied by count of provinces for the countries , and this will become more routes when moving to city and products.
You may say add something like
$router = $ctrl->getRouter();
$router->addRoute(
'country',
new Zend_Controller_Router_Route('country/:country/:province/:city/:product',
array('controller' => 'country',
'action' => 'index'))
);
But in this case its like we will be pointing to same action, but as the view of the requests change, and this will become a fat controller .
The problem with Zend_Controller_Router_Route_Regex is we should have something likeexample.com/en/country/spain/barcelona/barcelona/taxis
and also the all moves to a single action. As the view is entirely different, it becomes dirty. May be something like partials I can use. But I wonder whether there is another good solution for the problem to solve this. This is a legacy project, so I have limitations on it and #ZF version is 1.6.
There is an example something similar
http://www.travelportal.info/
http://www.travelportal.info/asia
http://www.travelportal.info/asia/india
http://www.travelportal.info/asia/india/business-currency-economy
How do you think, they have done this, will they have added routes atleast for asia , europe like that ?
I was able to make it work like
example.com/en/spain
Pointing to CountryController
indexAction
example.com/en/spain/barcelona
Pointing to CountryController
provinceAction
example.com/en/spain/barcelona/barcelona
Pointing to CountryController
cityAction
example.com/en/spain/barcelona/barcelona/taxis
Pointing to CountryController
productAction
But there I need to add 4 routes and this will become hard to manually add the route like this.
Suggestions and criticisms are welcome to make it better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您希望为每个示例场景都有一个单独的路线,例如:
It seems like you want a separate route for each of your example scenarios, e.g.: