试图找到解决方案,但我总是卡在文档或答案中包括其他捆绑包。在动态路由器的文档中,您可以找到提示:
“当然,你也可以有几个参数,就像普通的 Symfony 路由一样。模式、默认值和要求的语义和规则与核心路由完全相同。”
而已。
...
/foo/{id}/bar
我尝试了(似乎没有)一切来完成它。
所有尝试都相同:
我尝试过应用变量模式和子路由。
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route as PhpcrRoute;
$dm = $this->get('cmf_routing.route_provider');
$route = new PhpcrRoute();
$route->setPosition( $dm->find( null, '/cms/routes' ), 'foo' );
$route->setVariablePattern('/{id}');
$dm->persist( $route );
$child = new PhpcrRoute();
$child->setPosition( $route, 'bar' );
$dm->persist( $child );
$dm->flush();
有或没有默认值和要求只有'/foo/bar'和'/foo/*'返回匹配,但'/foo/1/bar'提示我“没有找到“GET /foo/1/bar 的路由” “”。
...
刚才我几乎完成了。
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route as PhpcrRoute;
$dm = $this->get('cmf_routing.route_provider');
$route = new PhpcrRoute();
$route->setPosition( $dm->find( null, '/cms/routes' ), 'example_route' );
$dm->persist( $route );
$route->setPrefix( '/cms/routes/example_route' );
$route->setPath( '/foo/{id}/bar' );
$dm->flush();
如果前缀是'/cms/routes'并且名称是'foo'一切正常。但既然我已经走到了这一步,指定一个说话的名字就会把它四舍五入。
谢谢指教!