I am using cakephp 2.1.0
I have a Post Controller that basically creates a Post that has id as integer, title, image as string
I have a controller action that can work with a view that allows me to upload a file and create a new Post record. The action is called admin_add
This is working.
However, I want to expose this action admin_add such that a desktop app built in Adobe Flex can call it.
Preferably I want to use RESTful actions.
Basically I want to create this action as a web service.
Most tutorials I see online tend to be for READ-only actions such as view and index.
What changes do I need to add to the cakephp application code?
I figured it out after sometime.
Assuming the following setup
Step 1. Install Webservice Plugin by josegonzalez.
Step 1.1. Setup Router::parseExtensions for json
Step 1.2. Add ‘Webservice.Webservice’ to the components of PostController
Step 1.3. Load the Plugin
Step 2. You need to change the following action for PostController
Step 3. Setup your Flex code as stated in this answer here. This is how you then retrieve the JSON response in Flex Actionscript.
Step 4. You should expect to get back a json response consisting of the 3 variables result, error, and id and the cake validationErrors. You may choose to blacklist validationErrors as stated in the plugin.