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

route bug or not? #470

Closed
s524797336 opened this issue Apr 19, 2017 · 3 comments
Closed

route bug or not? #470

s524797336 opened this issue Apr 19, 2017 · 3 comments

Comments

@s524797336
Copy link

s524797336 commented Apr 19, 2017

I'm using ci with vue, vue has it route, i set Home::index is vue's index.html
And i want route /api/(.*?)/(:any) -> \App\Controllers$1::$2
$routes->add('api/(.*?)/(:any)', '$1::$2'); $routes->add('(:any)', 'Home::index');
It doesn't work and i print some var find out $1 never changed only $2 changed, when i write like this
$routes->add('api/(.*?)/(:any)', '\App\Controllers\\\$1::$2'); $routes->add('(:any)', 'Home::index');
This will work, is this a bug or just it's way?

@lonnieezell
Copy link
Member

It's not a bug. It's the regular expressions that you're using. Both .* and (:any) are the same will return any character except a newline. That means that it's getting confused. What you're probably looking for is more along the lines of the :segment placeholder.

However, it also looks like you're basically re-creating the "magic" routing that CI has always had that matches up a controller/method with the URI segments. That feature still works in CI4.

@s524797336
Copy link
Author

s524797336 commented Apr 19, 2017

My English is not well, i actually mean \App\Controllers\\\$1::$2 is not equal \App\Controllers\$1::$2
Because the second kinds of "$1" will not analysis as an argument replacement but $2 will get replaced.
route http://host/api/Article/get/ will become $1/get
If use the first segment it will become Article/get and it's right.
Focus on \\\, why simple \ will not analysis "$1" as an argument?

@lonnieezell
Copy link
Member

Ah. When matching a namespace to a physical file, each directory is separated by a \ in the namespace name. So, have \\\ would make it attempt to look for two directories with an empty name, which can't exist. So that's the first possibility.

Second is how the escaping happens in the string itself. The combination of \\\$ in a single quoted string would break down like this, I believe:

  • the first slash escapes the second, telling the language that you want a single, real, slash there. This leaves us at \\$
  • the third slash is now escaping the $, making the dollar sign expected to be part of the literal string. If it's treated as a literal symbol, then $1 is no longer a placeholder but two literal characters that are expected to be in the filename. Which is not what you want.

So again, this is not a bug. That's a language issue you're dealing with there.

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

2 participants