需要在Zend Router中实现动态路由器参数分段。这个想法是:
网址为/route/:route/resource/:resource/:identifier
,并具有以下配置:
'orchestration.rest.dynamic-router' => array(
'type' => 'Segment',
'options' => array(
'route' => '/route/:route/resource/:resource[/:identifier]',
'defaults' => array(
'controller' => 'Controller',
),
),
),
需要使其支持n位数不同的key => value路由器参数,格式如下:
/route/:route/resource/:resource/:identifier/key1/value1/key2/value2/key3/value3
第二个问题是,仅当您提供了可选的:identifier参数时,此方法才有效。
这是我检查过的内容,但不确定如何实现此目标: https://docs.zendframework.com/zend-router/routing/#zend92router92http92segment
答案 0 :(得分:0)
留下静态路由。
1)将它们缓存以提高性能
2)如果您使用rest逻辑,请使用POST方法,而不是GET(URL中的参数)
'orchestration.rest' => array(
'type' => 'Segment',
'options' => array(
'routerest' => '/routerest/:action',
'defaults' => array(
'controller' => 'Controller',
),
),
),
(pseudo code)
datas={key1 : param1 , key2 : param2, etc...}
url=yourDomain/routerest/show (show=the action)
send Ajax Request(or something else in another langage with METHOD=POST)
... use post to consume rest action on server, with Ajax, or other...
datas={id1 : param1 , id2 : param2, etc...}
url=yourDomain/routerest/getdatas (getdatas=the action)
...在您的Controller.php中
...处理路线中的动作
function showAction() {
$request = $this->getRequest();
if ($request->isPost()) {
$param1=$this->params()->fromPost('key1','defaultvalue');
$param2=$this->params()->fromPost('key2','defaultvalue');
...
...
} else {... ERROR..}
}
...处理路由中的getdatas操作
function getdatasAction() {
$request = $this->getRequest();
if ($request->isPost()) {
$id1=$this->params()->fromPost('id1','defaultvalue');
$id2=$this->params()->fromPost('id2','defaultvalue');
...
...
if ($id1$=='all') { return $this->redirect()->toRoute ('otherroute', array ('action' => 'xxx', 'paramxxx' => 'xx'));
...
...
} else {... ERROR..}
}