Domanda

I'm fairly new to RESTful web services and even more new to the Recess PHP framework. It's easy to retrieve resources by ID. For example, if I want to retrieve a User with ID 7, I would make a request to:

http://localhost/myApp/user/7

What I'm wondering is this: is there an easy way to retrieve a resource by a different column, for example, a user's username?

http://localhost/myApp/user/username/tyler

This seems like it would be something pretty important for a RESTful framework to have, so I'm guessing there's a way to do this or a way to implement it easily.

È stato utile?

Soluzione

I figured out how to do this using the framework's parametric routing system. I created a function that can retrieve a User resource by a specified property value:

/** !Route GET, $property/$value */
function getUser($property, $value) {   
    $this->user = Make::a('User')->equal($property, $value)->first();  
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top