简体   繁体   English

如何在Sonata Admin中设置路由的主机?

[英]How to set host for routes in sonata admin?

How to make sonata always use root domain for url it generates? 如何使奏鸣曲始终使用根域生成的URL? I have a site, some of the pages are on the root domain, some are on the subdomain. 我有一个网站,有些页面在根域上,有些页面在子域上。 I need to have url to edit post that always refers to root domain even if the link is on the subdomain. 我需要使用url来编辑始终引用根域的帖子,即使该链接位于子域上也是如此。

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

It looks like I could solve the issue for sonata adding to sonata route options and defaults in routing.yml 看来我可以解决奏鸣曲添加到奏鸣曲路线选项和routing.yml中的默认值的问题

admin_area:
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /backoffice
    options:
        compiler_class: 'MyApp\Router\RouteCompiler'
    defaults:
        default_host: %router.request_context.host%

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /backoffice
    options:
        compiler_class: 'MyApp\Router\RouteCompiler'
    defaults:
        default_host: %router.request_context.host%

router.request_context.host is my root domain. router.request_context.host是我的根域。

The route compiler class looks like: 路由编译器类如下所示:

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

When I use in twig url function, it generates url to root domain even on pages from subdomain. 当我在细枝url函数中使用时,即使在子域的页面上,它也会生成到根域的url。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM