Comments (15)
Adding the {foo}? in the tail of route declaration make the request (see above) working perfectly,
BUT broke following request: /api/account/285/token/
:-(
from phroute.
May be make route string insensitive for query string (?...
)?
from phroute.
Adding get /api/account/{user_id:i}/token/
and get /api/account/{user_id:i}/token/{q}?
is only way for me now... And it seems as big workaround...
from phroute.
How are you dispatching the route?
There is no need to pass the query string into the route dispatcher.
Could you post your dispatch code?
Cheers
Joe Green
On 25 Sep 2014, at 18:39, Александр [email protected] wrote:
Adding get /api/account/{user_id:i}/token/
and get /api/account/{user_id:i}/token/{q}?is only way for me now...
—
Reply to this email directly or view it on GitHub.
from phroute.
I do it now:
$router->get('/api/account/{user_id:i}/token/', $get_tokens); // not working for /api/account/285/token/?name=info-product
$router->get('/api/account/{user_id:i}/token/{q}?', $get_tokens);
from phroute.
$get_tokens
is a lambda:
$get_tokens = function ($user_id) {
$token_name = !empty($_GET['name']) ? $_GET['name'] : '';
return \User\Token\get($user_id, $token_name);
};
from phroute.
No not the route collection. I need the dispatch code - something like this:
$dispatcher = new Phroute\Dispatcher($router);
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
from phroute.
Basically you are dispatching this:
$dispatcher->dispatch('GET', '/api/account/285/token/?name=info-product');
when you should be dispatching this:
$dispatcher->dispatch('GET', '/api/account/285/token/');
The router is not concerned with the query string. Hope that helps a little, but if you can post your dispatch code I'll take a look and see if I can help further.
from phroute.
$router->get('/api/account/{user_id:i}/token', $get_tokens);
is the correct set up for the route /api/account/285/token
from phroute.
My dispatcher is exactly same.
And i understood, what the root of this trouble now :-)
I must use following expression
parse_url($_SERVER["REQUEST_URI"])['path']
instead of simple $_SERVER["REQUEST_URI"]
in the dispatcher.
Thank you for right idea!
And thank you for grateful library!
from phroute.
Yeah! It working now.
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER["REQUEST_URI"])['path']);
What about updating example (in readme.md
) with above fix?
from phroute.
I see :) I will indeed update the readme. Thank you!
I rarely use the superglobals directly, and I had forgotten that the REQUEST_URI global contains the query string too. This should have occurred to me as soon as you posted this. My apologies.
I usually use something like this as a starting point for my web applications. Its not a framework, just a basic entry point for a web app, which in this case uses the symfony foundation request library to access the request information.
https://github.com/joegreen0991/framework/blob/master/app/app.php#L31
from phroute.
Done! Thanks for the feedback :)
from phroute.
I'm glade!
from phroute.
Please add this line to README, it's very helpful one :)
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER["REQUEST_URI"])['path']);
from phroute.
Related Issues (20)
- There was an error installing phroute in its latest version
- Error Class not found HOT 1
- Possible error to group routes
- Query string is not passing on real server HOT 1
- Handling exceptions within controller methods HOT 1
- Extends Controller Index optional parameter NOT ALLOWED HOT 2
- Cannot use the same placeholder 'id' twice HOT 1
- How to Use Before in Controllers
- Match any route to OPTIONS request method HOT 3
- Bug: Filters applied in registered order instead of requested order
- Custom resolver route parameters
- Error! when has too many variableRoutes
- how to prevent URL not found? HOT 2
- how handle route not found in dispatcher to redirect to 404 page
- Fatal error: Uncaught Phroute\Phroute\Exception\HttpRouteNotFoundException: Route ecomselim does not exist in HOT 2
- Not able to post with jquery. HOT 1
- Post with JQuery info
- Controller methods are call twice on every request
- route issue - URL not found HOT 1
- Bug with PHP 8.1 with RouteCollector class HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phroute.