SpliceIt! Controllers

Where do I put my SpliceIt! plugin controllers?

Well the first thing you have to do is to create a SpliceIt! Plugin, once you've done this you can put your controller Posts inside app/plugins/my_plugin/controllers/posts_controller.php (Posts is a sample name for you new controller).

Show me some Code

The code for your new controller is similiar to the one used in regular CakePHP. The class you extend is either SpliceItAppController or [Plugin]AppController (if you use your own [plugin]_app_controller.php):

The Code for creating a new controller named Posts (using no PluginAppController):
  1. class PostsController extends SpliceItAppController
  2. {
  3.     var $name = 'Posts';
  4. }
The Code for creating a new controller named Posts (using an own PluginAppController Todo):
  1. class PostsController extends MyPluginAppController
  2. {
  3.     var $name = 'Posts';
  4. }

Including Apis

Apis are the SpliceIt! way of letting different Plugins communicate with each other in order to exchange information or to manipulate each others Data. There are two kinds of Apis, required ones and optional ones Todo. Required Plugins will cause errors and ugly behavior when not installed, but optional ones will only cause the plugin run with less features. Here is how you would include some apis:

Here you see how to include 2 required and 2 optional apis in a controller
  1. class PostsController extends SpliceItAppController
  2. {
  3.     var $name = 'Posts';
  4.  
  5.     var $requiredApis = array('User', 'Rights');
  6.     var $optionalApis = array('Tags', 'AntiSpam');
  7. }

There also is a second way of including an Api assuming that the Api you want to include has not the same name as the plugin (because the plugin has more then one api for example). In this case you would include the Api by adding a [Plugin]/[Api] String to the array:

How to deal with plugins that have more then one Api
  1. class PostsController extends SpliceItAppController
  2. {
  3.     var $name = 'Posts';
  4.  
  5.     var $optionalApis = array('MyPlugin/ApiA', 'MyPlugin/ApiB');
  6. }

Using Apis

Now that you know how to include Apis, here is how to use them:

Here you see to use an Api inside of a controller
  1. class PostsController extends SpliceItAppController
  2. {
  3.     var $name = 'Posts';
  4.  
  5.     var $requiredApis = array('User', 'Rights');
  6.     var $optionalApis = array('Tags', 'AntiSpam');
  7.    
  8.     function index()
  9.     {
  10.         $this->UserApi->addUser('Jimbo');
  11.         $tags = $this->TagsApi->listTags();
  12.         // etc. ... Always $this->[Plugin]Api->[action]();
  13.     }
  14. }

Where to go now?

Now that you are familiar with SpliceIt! Controllers you might want to learn more about other types of SpliceIt! objects:

Or read about some other features of SpliceIt!: