[英]Symfony Url Generator producing different URLs from the same Route before and after login
我目前在自定義框架中使用Symfony內核和路由,我遇到了一個奇怪的問題。 使用相同的路線:
$collection->add('article_edit', new Route('/articles/edit/{alias}', array(
'_controller' => 'AppBundle:Article:edit'
)));
使用此Url Generator代碼
$url = $this->generateUrl('article_edit',array('alias' => 'test'));
登錄前,Url Generator會生成
/文章/編輯/測試
登錄后,它會產生
沒有任何改變,這里可能會發生什么,因為我一直想要相同的結果。
謝謝
我可以看到“/ articles / edit / test”和“ http:// localhost / testsite / articles / edit / test ”是相同的網址,只是網站網址不同。
如果您使用“generateUrl”方法,它將生成始終相同的URL。 它應該始終生成“ http:// localhost / testsite / articles / edit / test ”
$url = $this->generateUrl('article_edit',array('alias' => 'test', UrlGeneratorInterface::ABSOLUTE_URL));
也不要忘記在命名空間部分使用以下類
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
嘗試在app/config/services.yml
設置主機
parameters:
router.request_context.host: www.yourdomain.com
router.request_context.scheme: http
router.request_context.base_url: /your/path
更多信息: https : //symfony.com/doc/3.3/console/request_context.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.