在Zend Framework中路由国家,省,市,产品

Har*_*K T 3 zend-framework zend-route zend-router

这个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.

有一个类似的例子

http://www.travelportal.info/ http://www.travelportal.info/asia http://www.travelportal.info/asia/india http://www.travelportal.info/asia/india/business-货币经济

您如何看待,他们已经做到了这一点,他们是否会为亚洲,欧洲这样增加至少的路线?

我能够像它一样工作

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条路线,这将很难手动添加这样的路线.

欢迎提出建议和批评,以使其更好.

Tim*_*ain 5

您似乎想为每个示例场景分别设置一条路线,例如:

$router->addRoute(
    'product',
    new Zend_Controller_Router_Route(':lang/:country/:province/:city/:product', array(
        'controller' => 'country',
        'action' => 'product'
    ))
);

$router->addRoute(
    'city',
    new Zend_Controller_Router_Route(':lang/:country/:province/:city', array(
        'controller' => 'country',
        'action' => 'city'
    ))
);

$router->addRoute(
    'province',
    new Zend_Controller_Router_Route(':lang/:country/:province', array(
        'controller' => 'country',
        'action' => 'province'
    ))
);

$router->addRoute(
    'country',
    new Zend_Controller_Router_Route(':lang/:country', array(
        'controller' => 'country',
        'action' => 'index'
    ))
);
Run Code Online (Sandbox Code Playgroud)