繁体   English   中英

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

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

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

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

看来我可以解决奏鸣曲添加到奏鸣曲路线选项和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是我的根域。

路由编译器类如下所示:

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

当我在细枝url函数中使用时,即使在子域的页面上,它也会生成到根域的url。

暂无
暂无

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

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