Routes with several arguments

3 years ago

dqj
Member | 11
+
0
-

If I use this route:

$router[] = new Route('<presenter>/<action=dependents>/<type>/<id>[/<recursive>]');

no other route methods seem to function properly (they do not set their arg values). I can get this to work:

$router[] = new Route('<presenter>/<action=dependents>/<type>/<id>');

but it throws off other methods so they don't work.

Here is the full route table I'm trying to use:

`
public static function createRouter() {
$router = new RouteList;
$router[] = new Route(‘<presenter>/<action>[/<id>]’, ‘Homepage:default’);
$router[] = new Route(‘<presenter>/<action=dependents>/<type>/<id>’);
$router[] = new Route(‘<presenter=Sign>/<action=in>/<username>/<password>’);
return $router;
}
`

Last edited by dqj (2015-10-11 00:26)

3 years ago

dqj
Member | 11
+
0
-

There appears to be a collision between the Sign/in and the presenter/dependents rules. I've tried different orderings…

3 years ago

Aurielle
Member | 1283
+
0
-

You have to define more specific routes earlier. So, your routes would like something like this:

$router = new RouteList;
$router[] = new Route('sign/in/<username>/<password>', 'Sign:in');
$router[] = new Route('<presenter>/<action=dependents>/<type>/<id>', ???);
$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');

I have no idea what are you trying to do in the second route. Also, having password in routes is a VERY BAD idea and I strongly discourage you from doing this.

3 years ago

dqj
Member | 11
+
0
-

Aurielle wrote:

You have to define more specific routes earlier. So, your routes would like something like this:

$router = new RouteList;
$router[] = new Route('sign/in/<username>/<password>', 'Sign:in');
$router[] = new Route('<presenter>/<action=dependents>/<type>/<id>', ???);
$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');

I have no idea what are you trying to do in the second route. Also, having password in routes is a VERY BAD idea and I strongly discourage you from doing this.

The routes are for an API service that returns JSON objects to Angular AJAX requests. All the presenters return JSON. Every object uses the same URL format, such as object/get/id and object/dependents/id, where object is the model, such as member or organization.

The login route is just a test to learn routing, and apparently a good one, since it has this problem.

3 years ago

dqj
Member | 11
+
0
-

I found an existing restful router package, which might be the best way for me to go:

https://github.com/drahak/Restful

3 years ago

Azathoth
Member | 506
+
0
-

if you need rest router, here in this project is another one https://github.com/…-api-sandbox?…