【发布时间】:2014-09-25 10:52:11
【问题描述】:
当父路由和子路由具有共同/相同的参数时,我无法使用 URL 视图助手创建正确的 url。
我的网址配置:
'contact' => array(
'type' => 'Segment',
'options' => array(
'route' => '/contact[/:contact][/action/:action]',
'constraints' => array(
'contact' => '[0-9]+',
'action' => '[a-zA-Z_-]+',
),
'defaults' => array(
'controller' => 'CrmContact',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'task' => array(
'type' => 'Segment',
'options' => array(
'route' => '/task[/:task][/action/:action]',
'constraints' => array(
'task' => '[0-9]+',
'action' => '[a-zA-Z_-]+',
),
'defaults' => array(
'controller' => 'CrmTask',
'action' => 'index',
),
),
),
)
)
由于很明显父路由和子路由都包含参数“action”,因此直接调用此路由时效果很好,这意味着如果您使用 '/contact/1/task/1/action/edit' all 访问浏览器是上帝。尝试使用 viewhelper Url 构造此 url 时会出现问题
$this->url('contact/task', array('contact' => $contact->id,'task' => $task->id, 'action' => 'edit'))
这会产生错误的网址,即
/contact/1/action/edit/task/1 instead of
/contact/1/task/1/action/edit
助手基本上从子路由中劫持动作参数并将其用于父路由...我不能停止使用参数“动作”,因为它是跨控制器方法路由请求的框架方式的一部分。 ..
【问题讨论】:
标签: php zend-framework2