因此,我尝试将代码重定向到控制器http://localhost/salesorder/view?id=5509c273f948e7cf068b456a内的另一个操作,此视图操作正常。但每次重定向代码运行时,它都会将我重定向到http://localhost/salesorder?id=5509c273f948e7cf068b456a
我现在无能为力,我做错了什么。
$params = ['controller' => 'SalesOrder',
'action' => 'view',
];
$options = ['query' => ['id' => (string) $orderId]];
return $this->redirect()->toRoute('Salesorder', $params, $options);
我的moduleconfig看起来像这样
'Salesorder' => array(
'type' => 'Literal',
'options' => array(
'route' => '/salesorder',
'defaults' => array(
'__NAMESPACE__' => 'Backend\Controller',
'controller' => 'SalesOrder',
'action' => 'new',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/:action]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'action' => 'new'
),
),
),
),
),
答案 0 :(得分:1)
请原谅我无法发表评论,因为我没有足够的声誉,但这可能会引导您找到解决方案:
首先修复toroute函数调用:
return $this->redirect()->toRoute('Salesorder', array('id'=> (string) $orderId));
然后将路线规范修改为:
'Salesorder' => array(
'type' => 'segment',
'options' => array(
'route' => '/MODULE_NAME/SalesOrder/new/:id[/]',
'constraints' => array(
'id' => '[a-zA-Z0-9_-]*'
),
'defaults' => array(
'controller' => 'MODULE\Controller\SalesOrder',
'action' => 'new',
),
),
),