Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:59:39+00:00 2026-06-05T12:59:39+00:00

I am using cakephp 2.1.0 I have a Post Controller that basically creates a

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:59:40+00:00Added an answer on June 5, 2026 at 12:59 pm

    I figured it out after sometime.

    Assuming the following setup

    • Cakephp 2.x
    • the action here is public for anonymous users

    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

        public function add() { 
        
        if ($this->request->is('post')) {
    
            // create new Post -- this will grab the file from the request data
            $newPost = $this->Post->createNew($this->request->data);
        
            if ($newPost) {
                $this->Session->setFlash(__('Your Post has been saved'));
                // for normal webpage submission
                if (empty($this->request->params['ext'])) {
                    $this->redirect('/');                   
                } else {        
                    // for json response to Flex client 
                    $result = $newPost;
                    $error = null;
                    $id = null;
                }
            } else {
                $this->Session->setFlash(__('Your Post could not be saved. Please, try again.'));
                // for json response for failure to create
                if (!empty($this->request->params['ext'])) {
                
                        
                        $result = null;
                        $error = 'Your Post could not be saved.';
                        $id = null;
                
                }
                
            }
            // this is for json response via Webservice.Webservice
            $this->set(compact('result', 'error', 'id'));
            
        }
    
        }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using cakephp 2.0 and i have data submitted that i want to cleanup,
I'm building a prototype search application using CakePHP and I have a search controller
using cakephp on email column in the db i have unique constraint, how can
I have built a contact form using CakePHP on my site. The controller logic
I have only recently started using CakePHP and have been unable to get validation
I am using CakePHP framework with MySQL database and I have problem in saving
I have made a full application in JQM using cakePHP as the server side
I'm using CakePHP but it's a question about the MVC pattern. I have in
I just started using CakePHP for a small project. I have rails experience, and
I am using CakePHP 2.0's integrated Auth component. I have the following tables :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.