I currently using Symfony Kernel and Routing within a custom framework and I have run into a curious problem. Using the same Route:
$collection->add('article_edit', new Route('/articles/edit/{alias}', array(
'_controller' => 'AppBundle:Article:edit'
)));
Using this Url Generator code
$url = $this->generateUrl('article_edit',array('alias' => 'test'));
Before login, the Url Generator produces
/articles/edit/test
And after login, it produces
Without anything being changed, what could be happening here since I want the same result consistently.
Thanks
I can see that "/articles/edit/test" and " http://localhost/testsite/articles/edit/test " are same url just with difference of site url in it.
if you use your "generateUrl" method as following it will generate always same url. It should generate " http://localhost/testsite/articles/edit/test " always
$url = $this->generateUrl('article_edit',array('alias' => 'test', UrlGeneratorInterface::ABSOLUTE_URL));
Also dont forget to use following class in namespace section
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Try setting your host in app/config/services.yml
parameters:
router.request_context.host: www.yourdomain.com
router.request_context.scheme: http
router.request_context.base_url: /your/path
More Info: https://symfony.com/doc/3.3/console/request_context.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.