f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
208 stars 87 forks source link

Alias and relative path problem #322

Open chaosflaws opened 7 years ago

chaosflaws commented 7 years ago

My f3 app is in a subdirectory of the server's document root. Therefore, I am using a <base ...> directive for relative URLs. Now I tried to use the alias filter to generate relative URLs from named routes:

<a href="{{ 'some_route' | alias }}">{{ @some_text }}</a>

The route looks somewhat like this:

$f3->route('GET @some_route: /some_path', 'Page\Start->display');

However, as the routes are prepended with a slash, the resulting URL is /some_path, which is an absolute path. Right now, I am using a custom filter to simply delete the leading slash, but maybe something built-in would come in handy?

Just as a little side note, the syntax for chaining filters seemed unintuitive to me. I tried the obvious | alias | my_filter. Any reason filters are separated by commas?

ikkez commented 7 years ago

Known problem here too 🖐 I also use a custom alias filter that overwrites the default behaviour to get around this. I'm not sure if we can safely change this.. I use a <base> tag in most of my projects but for those who include the sub-dir in every link it'll break of course. 🤔

xfra35 commented 7 years ago

I don't use the <base> tag (mostly because of the hash anchors breaking), which means I have to prefix every link with BASE, but a handy filter does it for me:

<a href="{{ some_route | url }}">{{ @some_text }}</a>

Maybe we could tweak the default alias filter, since it doesn't fit either devs (those who use <base> and those who don't)? If it did automatically prefix the alias with BASE, it would work in every situation. We could rename it to path or uri to avoid confusion with the alias() function and also to maintain BC.

xfra35 commented 7 years ago

@chaosflaws you wrote:

Just as a little side note, the syntax for chaining filters seemed unintuitive to me

There's a long-running issue on this topic.

chaosflaws commented 7 years ago

@xfra35

Maybe we could tweak the default alias filter, since it doesn't fit either devs (those who use and those who don't)? If it did automatically prefix the alias with BASE, it would work in every situation.

I think this is a sensible solution.