簡體   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