As to leave available a GET parameter after circumcision?

circumcision :)
private static function removeQueryString($url)
{
 if ($url) {
 $params = explode('&', $url, 2); // cut something ?page=1
 if (strpos($params[0], '=') === false) {
 $params = explode('/', $params[0]); // cut before the first slash
 return rtrim($params[0], '/'); // back clean the name of the controller
}
}
 return ";
 }

rules
Router::add('^operation$', ['controller' => 'Operations', 'action' => 'operation']); // 'id' => 1, somehow it is necessary
Router::add('^$', ['controller' => 'Main']);
Router::add('^(?P<controller>[a-z]+)/?(?P<id>\d+)?$');
Router::add('^(?P<controller>[a-z]+)/?(?P<action>[a-z]+)?/?(?P<id>\d+)?$');

Now if I turn on /operation/1, then everything is fine - worked rule 1, but there is no GET parameter id with a value of 1
Array
(
 [controller] => Operations
 [action] => operation
 here it is necessary to obtain [id] => 1 
)


that is, rule 3 is of course not fulfilled. How to leave id? To add to the rule? How to pass a value in a rule?
April 4th 20 at 13:12
1 answer
April 4th 20 at 13:14
can it is necessary to immediately break the whole string, not to be confused?
function.parse-str.php
thanks for stopping by, but decided
Router::add('^operation-(?P<oid>\d+)/missions$', ['controller' => 'Operations', 'action' => 'missions']);

/operation-2/missions
Array
(
 [controller] => Operations
 [action] => missions
 [oid] => 2
)

from the router throw in a controller and use - Julien84 commented on April 4th 20 at 13:17

Find more questions by tags PHP