SpliceIt! APIs
Abstract
In SpliceIt!, APIs are some kind of "abstract controller". The functions defined in your API can (and usually will) be used in your controllers. However, as APIs should always be more abstract than controllers, you should not call controller actions out of an API.
Furthermore, APIs are used to communicate between plugins (so they are somehow similar to components, but whereas components can only be used to communicate between the controllers of one plugin, the main purpose of an API is to enable communication between different plugins).
Most plugins will offer one, some even several APIs.
Where to put my API?
An API is located in "app/plugins/[my_plugin]/apis/[Api]_api.php", whereby [Api] should be
- the name of your plugin, if it provides only one API
- a word of your choice that describes the API as good as possible if your plugin has more than one API.
Basic API design
Most of the time APIs behave quite similar to controllers.
Each API extends the Api-class, and should either be named "[Plugin]Api", or "[Plugin][Api]Api" if you have more than one API.
(the Api class is based on the controller class, but unneeded controller stuff as rendering and helpers is disabled Todo.
To use models in your API, just add the variable $uses to your API (it works the same way as with controllers). You can only use the models of your plugin. If you have to access the data of another plugin, you may of course include it's API.
You can also use other APIs in your API by setting the $requiredApi and/or $optionalApi variables (as in controllers).
Example of what an API could look like:- class UserApi extends Api
- {
- // use the models 'User' and 'Rights'
- function createUser($name, $password, $email)
- {
- ...
- }
- function findUsers($condition) {
- return $this->User->findAll($condition, "ID, name, email");
- }
- function checkPermission ($user_id, $action) {
- if ($this->Rights->find("WHERE user_id IS '".$user_id."' AND action IS '".$action."'"))
- return TRUE;
- else
- return FALSE;
- }
- }
Where to go now?
Now that you are familiar with SpliceIt! Apis you might want to learn more about other types of SpliceIt! objects:
Or read about some other features of SpliceIt!:
SpliceIt!-Documenation v0.1 ALPHA (generated on 28.03.2006)