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 7129885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:17:26+00:00 2026-05-28T11:17:26+00:00

I’m new to cakephp. I’m using the 2.0.5 release, according it looks like rails

  • 0

I’m new to cakephp. I’m using the 2.0.5 release, according it looks like rails on a large bunch of points it is pretty easy to get things done.

I’m currently using it to build an REST api for a game. It is easy to build an REST controller, but can’t find a way to get nested ressources.

I mean in rails it is easy like hell to get something like this : controller1/id/controller2/id.

I have an hard time to find a way to do this in cakephp. The mapresources method don’t seem to support multilevel rest api. Am i wrong?

How can i do a multi level rest API in cakephp 2?

  • 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-05-28T11:17:27+00:00Added an answer on May 28, 2026 at 11:17 am

    So, i succeed to build my own generator.

    According to the fact you provide an array(“parent_controller” => “child_controller”).

    This way you can generate for superhero => superpowers

    superheros/1/superpowers/ (here with or withouth ids according to your routes.

    Args mappeds to method args so function index($superhero_id)

    function generateNestedResources($array)
        {
    
            foreach($array as $key=>$value)
            {
                //Index -GET /
                 Router::connect('/'.$key.'/:'.$key.'_id/'.$value,
                    array('controller' => $value,'action' => 'index','method' => 'GET'),
                    array( $key.'_id' => '[0-9]+','pass' => array($key.'_id')));
                // View -GET /id
                Router::connect('/'.$key.'/:'.$key.'_id/'.$value.'/:id',
                    array('controller' => $value,'action' => 'view','method' => 'GET'),
                    array('id' => '[0-9]+', $key.'_id' => '[0-9]+','pass' => array($key.'_id','id')));
    
                //add -POST/
                 Router::connect('/'.$key.'/:'.$key.'_id/'.$value,
                    array('controller' => $value,'action' => 'add','method' => 'POST'),
                    array( $key.'_id' => '[0-9]+','pass' => array($key.'_id')));
                //edit -PUT/ID
                 Router::connect('/'.$key.'/:'.$key.'_id/'.$value.'/:id',
                    array('controller' => $value,'action' => 'edit','method' => 'PUT'),
                    array('id' => '[0-9]+', $key.'_id' => '[0-9]+','pass' => array($key.'_id','id')));
    
                //delete -DELEte /ID
                 Router::connect('/'.$key.'/:'.$key.'_id/'.$value.'/:id',
                    array('controller' => $value,'action' => 'delete','method' => 'DELETE'),
                    array('id' => '[0-9]+', $key.'_id' => '[0-9]+','pass' => array($key.'_id','id')));
    
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.