Giter Club home page Giter Club logo

Comments (15)

a-x- avatar a-x- commented on July 16, 2024

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.

a-x- avatar a-x- commented on July 16, 2024

May be make route string insensitive for query string (?...)?

from phroute.

a-x- avatar a-x- commented on July 16, 2024

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.

mrjgreen avatar mrjgreen commented on July 16, 2024

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.

a-x- avatar a-x- commented on July 16, 2024

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.

a-x- avatar a-x- commented on July 16, 2024

$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.

mrjgreen avatar mrjgreen commented on July 16, 2024

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.

mrjgreen avatar mrjgreen commented on July 16, 2024

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.

mrjgreen avatar mrjgreen commented on July 16, 2024

$router->get('/api/account/{user_id:i}/token', $get_tokens); is the correct set up for the route /api/account/285/token

from phroute.

a-x- avatar a-x- commented on July 16, 2024

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.

a-x- avatar a-x- commented on July 16, 2024

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.

mrjgreen avatar mrjgreen commented on July 16, 2024

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.

mrjgreen avatar mrjgreen commented on July 16, 2024

Done! Thanks for the feedback :)

from phroute.

a-x- avatar a-x- commented on July 16, 2024

I'm glade!

from phroute.

 avatar commented on July 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.