Download the PHP package openbuildings/jam-resource without Composer
On this page you can find all versions of the php package openbuildings/jam-resource. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download openbuildings/jam-resource
More information about openbuildings/jam-resource
Files in openbuildings/jam-resource
Package jam-resource
Short Description Kohana resources for Jam ORM which connect routes, controllers and models
License ICS
Homepage https://github.com/openbuildings/jam-resource
Informations about the package jam-resource
Resource Jam module for Kohana 3.3
Resources act as a bridge between routes, models and requests.
The jam-resource
module works with the mighty Jam ORM for Kohana 3.3
Main Features
- Define resources in your bootstrap and routes for them would automatically be created
- Generate urls from model objects or collections
- Nest resources
- Access the model object, the model collection or the parent object for the current request
- Supports slugs with the sluggable behavior in Jam ORM
- Restrict routes (and actions) to certain HTTP methods
- Easily build a RESTful API
Defining resources
The simplest way to define a resource:
This would generate seven routes which would serve these purposes:
HTTP Verb | path | action | used for |
---|---|---|---|
GET | /users | index | display a list of all users |
GET | /users/new | new | return an HTML form for creating a new user |
POST | /users | create | create a new user |
GET | /users/1 | show | display a specific user | GET | /users/1/edit | edit | return an HTML form for editing a user |
PUT | /users/1 | update | update a specific user |
DELETE | /users/1 | destroy | delete a specific user |
As you can see every action has a very specific purpose. Something you might not be used to in the PHP world. Everything is derived from Ruby on Rails routing.
You can easily limit the creation of these default routes or add more:
Only specific routes
Default routes except some
Adding additional routes
This would make accessible the following URLs (in addition to the default ones):
- /users/1/picture
- /users/featured
Of course you can use these options together to define those routes your application would need.
The routes which a resource would generate are separated in member routes and collection routes. The collection routes do not have a specific id while the member routes are about a specific resource.
As said above the resources act as a glue between routes, models and controllers.
The model, the controller and the URI paths are derived from the resource name.
The users
resource would guess the controller is Controller_Users
and the model is Model_User
.
You can easily specify these explicitly:
This would still create routes to access the photos on /photos
and /photos/1
.
But it would use the actions in Controller_Pictures
and the image model.
Changing the path string is achieved using the path
option:
This would create routes for URIs like: /people
, /people/1
etc. while still using the users controller and user model.
Accessing resources in controllers
When you visit /users
the generated routes would open Controller_Users::action_index()
.
From there you would be able to access a Jam_Collections for the user model with:
$this->request->resource()->collection()
You could also access a Jam_Builder with:
$this->request->resource()->builder()
When you visit /users/1
the routes would open Controller_Users::action_show()
.
From there you could access the specified user model with:
$this->request->resource()->object()
There is no need to check if it is loaded. If there is no user model with the specified id
Jam_Exception_Notfound
would be thrown.
Generating URLs
You could also generate the resourceful URLs for a specific model or a collection.
Use the
Child resources
TODO: explain child resources - defining, usage and application
Singular resources
TODO: explain what singular resources are and how they should be used
Sluggable
You could use the sluggable
(TRUE
|FALSE
) option and the slug_regex
to set up
the routes to use slugs instead of primary keys.
TODO: explain sluggable implementation here
Formats
TODO: explain formats here
LICENSE
© Copyright Despark Ltd. 2012
License