Fork me on GitHub


The modules are easily identifieable by their directory and file structure. For every module there is (usually the same as the route) a directory path, and for every action (INDEX, GET, POST, PUT, DELETE) there is a php file in that directory. If an action php file is not present, a 501 Not implemented status code is returned.

So this can be an example directory structure

| modules
|- forum
--|- posts
----|- delete.php
----|- get.php
----|- index.php
----|- post.php
----|- put.php
|- index.php

This means that the GET call to /forum/posts translates to modules/forum/posts/index.php and the GET call to /forum/posts/id/27671 translates to modules/forum/posts/get.php (with $this->getFilterParameters() returning array("id" => 27671)).

I noticed that in a lot of cases, the INDEX action is the same as GET without the parameters. If this is the case in a resource, I usually put in include of the get.php in the index.php so I only have to deal with changes in one file.

Resource module directory structures can go as deep as you like. As long as you don't forget to add the resource to the Router it will work instantly.