symfony - 如何在奏鸣曲管理员中为路由设置主机?
问题描述
如何让奏鸣曲始终使用根域作为它生成的 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);
}
}
当我在 twig url 函数中使用时,即使在来自子域的页面上,它也会生成根域的 url。
推荐阅读
- fish - 如何在 Fish Shell 中获取完整的当前命令
- c - STM32L073 LQFP100 - 添加石英不起作用
- flutter - 2 I/GDPAndroid(28712):getCpuTemperature 有效路径:/sys/class/thermal/thermal_zone0/temp
- java - BigQuery 存储写入 API 日期时间
- c++ - 从文件中读取大端数据的最佳方法
- html - VS Code 未显示在 chrome 上
- asp.net - 如何在同一个 VM 中部署网站和 Web API
- ios - XCUITest - 测试运行器在启动后从未开始执行测试
- c++ - 声明 const 时模板成员函数解析失败
- html - 如何通过 Google 协作平台上的嵌入式代码访问 Google Drive 上的公共图像?