0

so far I have worked only with integer values as request parameters in urls.

Now I need to work with strings which contain spaces etc. for example: "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

I'm sure the problem are the spaces, so my question a bit more detailed, can I quote or somewhat the routing parameter?

pia-sophie
  • 505
  • 4
  • 21
  • It is `string` by default, isn’t it? – gsc Nov 01 '17 at 07:51
  • It might be the 'constraints' key in the route options array that is causing it to fail, integer values would be using something like '[0-9]*' that wouldn't work with your example if you copied and pasted the config from another route. – avy Nov 02 '17 at 17:59
  • it must be string, because the file is imported and this string column is the only identification I get there. Because of law reasons this file can't be changed or get additional columns. – pia-sophie Nov 07 '17 at 13:54

1 Answers1

0

SOLVED: my regular expression in the routing was wrong, I changed it to:

 'id'     => '[a-zA-Z0-9\-\. /]*',
pia-sophie
  • 505
  • 4
  • 21