简体   繁体   English

请求参数$ id中的数据类型= $ this-> params()-> fromRoute('id');

[英]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.

相关问题 ZF3:$ request-&gt; getQuery(&#39;my_var&#39;)与$ this-&gt; params()-&gt; fromQuery(&#39;var_name&#39;)? - ZF3: $request->getQuery('my_var') vs $this->params()->fromQuery('var_name')? $ this-&gt; addElement(&#39;type&#39;,&#39;id&#39;,array(&#39;specs&#39;))VS new Zend_Form_Element_Type(&#39;id&#39;); - $this->addElement('type', 'id', array('specs')) VS new Zend_Form_Element_Type('id'); $ this - &gt; _ request-&gt; isXmlHttpRequest()不工作 - $this->_request->isXmlHttpRequest() Not Working 如何从 Laminas 中的 url 参数中获取 $id? - How to get $id from url parameter in Laminas? 如果刷新网页,如何停止if($ this-&gt; _ request-&gt; isPost())? - how to stop if($this->_request->isPost()) if webpage is refreshed? Zend 框架 $this->_request->isXmlHttpRequest() IE7/8 - Zend Framework $this->_request->isXmlHttpRequest() IE7/8 Zend_GData Spreadsheet - grid-id的查询参数值无效 - Zend_GData Spreadsheet - Invalid query parameter value for grid-id 没有提供ID的资源上的PUT请求的正确HTTP状态代码是什么? - What is the correct HTTP status code for a PUT request on a resource without supplying an id? 子菜单在获取请求参数时未显示 - submenu not showing when having get request params Zend上的请求参数不起作用 - Request parameter on Zend not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM