如何在奏鸣曲管理中设置路由主机?



如何使奏鸣曲始终使用根域作为它生成的网址? 我有一个网站,有些页面在根域上,有些在子域上。 我需要有网址来编辑始终引用根域的帖子,即使链接位于子域上。

<a href="{{ path('admin_prefix_post_post_edit', {id: post.id}) }}" rel="nofollow" target="_blank">Edit</a>

看起来我可以解决奏鸣曲的问题 在 routeting.yml 中添加奏鸣曲路由选项和默认值

admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /backoffice
options:
compiler_class: 'MyAppRouterRouteCompiler'
defaults:
default_host: %router.request_context.host%
_sonata_admin:
resource: .
type: sonata_admin
prefix: /backoffice
options:
compiler_class: 'MyAppRouterRouteCompiler'
defaults:
default_host: %router.request_context.host%

router.request_context.host是我的根域名。

路由编译器类如下所示:

class RouteCompiler extends BaseRouteCompiler
{
public static function compile(Route $route)
{
if ($route->getHost() === "") {
$route->setHost($route->getDefaults()['default_host']);
}
return parent::compile($route);
}
}

当我在 twig url 函数中使用时,它甚至在 子域中的页面。

最新更新