您可以为此编写自定义解决方案,但是每次您需要更多东西时都会显示轮子,这就是我的建议使用最佳实践的原因:
composer require symfony/routing
<?php
require './vendor/autoload.php';
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
$route = new Route(
'/movie/english/{slug}/edit/{id}/{title}',
array('controller' => 'MyController')
);
$routes = new RouteCollection();
$routes->add('route_name', $route);
$context = new RequestContext();
$matcher = new UrlMatcher($routes, $context);
$parameters = $matcher->match('/movie/english/scorpion/edit/125/E01E05');
var_dump($parameters);
将打印:
数组(大小=5)
'控制器' => 字符串'MyController' (长度=12)
'slug' => 字符串'scorpion'(长度=8)
'id' => 字符串'125'(长度=3)
'title' => 字符串'E01E05'(长度=6)
'_route' => 字符串'route_name'(长度=10)
我真的相信这是最好的解决方案,希望它会帮助你。