Routing with array

Hello!

Maybe you know about route from phpleague.
Do you know how can I map an array to the router (symphony has is similar)

Example:
Url: app.com/3.1/service/232 → route: '/{version}/service/{account}'

How can I write the route for
Url: app.com/3.1/service/?account[]=232&account[]=241
Or, how can I send an array to the server via GET

Any idea?
Thank you!

Read the docs. It shows you how to do this is the documentation:

http://route.thephpleague.com/getting-started/

The part you need:
http://route.thephpleague.com/wildcard-routes/

I did :slight_smile: There’s nothing about array arguments.
Looks like it’s easier than I thought

I only have to map app.com/3.1/service/ in the router
and I can get the request with $request->get('account')

Sorry about the extra topic but maybe someone will use this info.

The $_GET paramas are the wildcards in the route.

http://route.thephpleague.com/wildcard-routes/

Take the example in the link above:

$router->addRoute('GET', '/user/{id}/{name}', function (Request $request, Response $response, array $args) {
    // $args = [
    //     'id'   => {id},  // the actual value of {id}
    //     'name' => {name} // the actual value of {name}
    // ];

    return $response;
});

The route: /user/{id}/{name} will match if you go to: /user/4/joe

You can access them using the $args array() as shown in the example, or call them from within the controller.

$args['id'] = 4
$args['name'] = joe

You did not understand my issue.

[quote]How can I write the route for
Url: app.com/3.1/service/?account[]=232&account[]=241
Or, how can I send an array to the server via GET[/quote]

There is no answer to this in that page.
The answer is the get method.

$router->addRoute(
    'get', $routePath,
    function($request, $response, $args) {
        var_dump($request->get()); // this is what I needed
        return $response;
    }
);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.