Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support base prefix for url generator #183

Open
xepozz opened this issue Dec 20, 2022 · 6 comments
Open

Support base prefix for url generator #183

xepozz opened this issue Dec 20, 2022 · 6 comments

Comments

@xepozz
Copy link
Member

xepozz commented Dec 20, 2022

I want to write an application that will live under some path, e.g. /blog
So I have two ways to write my urls:

  1. Each route should contain /blog
  2. Add a prefix to url generator that will automatically add the prefix to all further urls

If I choose the first option that I need to rewrite all my urls when I want to move from /blog to /.
There are more problems than I described above: proxying, making extensions and etc.

@xepozz
Copy link
Member Author

xepozz commented Dec 20, 2022

Here is a workaround now. Place that code into config/bootstrap.php.

<?php

declare(strict_types=1);

return [
    function (\Psr\Container\ContainerInterface $container) {
        $urlGenerator = $container->get(\Yiisoft\Router\UrlGeneratorInterface::class);
        $urlGenerator->setUriPrefix('/blog');
    },
];

But be careful, because the SubFolder middleware may not affect it.

@samdark
Copy link
Member

samdark commented Dec 20, 2022

@xepozz
Copy link
Member Author

xepozz commented Dec 20, 2022

Also current debugger doesn't understand the SubFolder prefix.
Also assets package has different approach to configure base path

@xepozz
Copy link
Member Author

xepozz commented Dec 20, 2022

https://github.com/yiisoft/router/blob/master/README.md#route-groups

It's not a group. It's a base url.

@vjik
Copy link
Member

vjik commented Jan 8, 2023

In router url generator already support this via setUriPrefix() method. The problem is in yiisoft/assets package that does not take it into account.

Seems, adding router dependency to assets package is a bad idea. Maybe we can resolve this problem via configuration of packages or application templates.

@rustamwin
Copy link
Member

Worth a look. I'm checking...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants