使用 Pimcore 从控制器内部反向构造自定义路由 5.x
Reverse construction of Custom Routes from inside a Controller using Pimcore 5.x
根据 Pimcore 5 文档:
URLs are generated using the default URL helper of Symfony $this->path() and $this->url(). Additionally to the standard helpers for generating URLs, Pimcore offers a special templating helper ($this->pimcoreUrl()) to generate URLs like you did with Pimcore 4. You can define a placeholder in the reverse pattern with %NAME and it is also possible to define an optional part, to do so just embrace the part with curly brackets { } (see example below).
https://pimcore.com/docs/5.0.x/Development_Documentation/MVC/Routing_and_URLs/Custom_Routes.html
我应该能够像这样使用路径方法反向构建路由:
$this->path( 'MyRouteName', [
'route_param_a' => 'A',
'route_param_b' => 'B',
'route_param_c' => 'C'
] );
不幸的是,当我从控制器内部调用它时,出现以下错误:
Attempted to call an undefined method named "path" of class "AppBundle\Controller\MyController".
当我直接从控制器(不使用视图)响应我的 JSON 对象时,控制器范围内是否有类似的函数或方法可用于生成我的路径?
看起来 Pimcore 5 文档中没有涵盖这个问题的答案,而是 Symfony 3 文档中!
https://symfony.com/doc/current/routing.html#generating-urls
$url = $this->generateUrl( 'MyRouteName', [
'route_param_a' => 'A',
'route_param_b' => 'B',
'route_param_c' => 'C'
] );
根据 Pimcore 5 文档:
URLs are generated using the default URL helper of Symfony $this->path() and $this->url(). Additionally to the standard helpers for generating URLs, Pimcore offers a special templating helper ($this->pimcoreUrl()) to generate URLs like you did with Pimcore 4. You can define a placeholder in the reverse pattern with %NAME and it is also possible to define an optional part, to do so just embrace the part with curly brackets { } (see example below).
https://pimcore.com/docs/5.0.x/Development_Documentation/MVC/Routing_and_URLs/Custom_Routes.html
我应该能够像这样使用路径方法反向构建路由:
$this->path( 'MyRouteName', [
'route_param_a' => 'A',
'route_param_b' => 'B',
'route_param_c' => 'C'
] );
不幸的是,当我从控制器内部调用它时,出现以下错误:
Attempted to call an undefined method named "path" of class "AppBundle\Controller\MyController".
当我直接从控制器(不使用视图)响应我的 JSON 对象时,控制器范围内是否有类似的函数或方法可用于生成我的路径?
看起来 Pimcore 5 文档中没有涵盖这个问题的答案,而是 Symfony 3 文档中!
https://symfony.com/doc/current/routing.html#generating-urls
$url = $this->generateUrl( 'MyRouteName', [
'route_param_a' => 'A',
'route_param_b' => 'B',
'route_param_c' => 'C'
] );