[英]datatype in request parameter $id = $this->params()->fromRoute('id');
so far I have worked only with integer values as request parameters in urls. 到目前为止,我只使用整数值作为url中的请求参数。
Now I need to work with strings which contain spaces etc. for example: "xyz 666 888-VCT" 现在,我需要使用包含空格等的字符串,例如:“ xyz 666 888-VCT”
I send the route and parameters out of my view script: 我从视图脚本中发送了路由和参数:
<a href="<?= $this->url('pcb', ['action' => 'index', 'id' => $rs->Part_Number]) ?>">PCB</a>
I try to get it within my controller action: 我尝试在控制器动作中获取它:
$id = $this->params()->fromRoute('id');
How is the right way to catch a string value in this case? 在这种情况下如何正确捕获字符串值?
edit: here additional my routing paramters: 编辑:这里另外我的路由参数:
'pcb' => [
'type' => Segment::class,
'options' => [
'route' => '/pcb[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
],
'defaults' => [
'controller' => Controller\PcbController::class,
'action' => 'index',
],
],
],
I get always 我总是
the requested url could not match by routing
请求的网址与路由不匹配
My url looks like follows: ...pcb/index/3441 99901 B 03 2519 xyz 我的网址如下所示:... pcb / index / 3441 99901 B 03 2519 xyz
I'm sure the problem are the spaces, so my question a bit more detailed, can I quote or somewhat the routing parameter? 我确定问题出在空格,所以我的问题更详细了,我可以引用还是略微引用路由参数?
解决:我在路由中的正则表达式是错误的,我将其更改为:
'id' => '[a-zA-Z0-9\-\. /]*',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.