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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:52:29+00:00 2026-05-23T19:52:29+00:00

Let me start out by saying I’ve tried to read the CakePHP book as

  • 0

Let me start out by saying I’ve tried to read the CakePHP book as much as I can for this particular topic, and for whatever reason, I just cannot figure this out.

I have a few models:

Person

  • each person can have many jobs
  • each job has one branch and each branch belongsTo one city.

At first I was relying on recursive, but its not customizable enough (obviously) do get the data that I want.

https://github.com/jwg2s/temp

I either get WAY too much data in my output array, or hardly any at all.. I just can’t figure this containable out, and if I could see an example of what I’m trying to do it would be great…

Thanks

  • 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-23T19:52:30+00:00Added an answer on May 23, 2026 at 7:52 pm

    since you’ve read the Cookbook up and down I won’t go through all the basic details with you and just try to explain how to use the containable.

    You can use the containable with the find-functions from your models. Either from your controller or directly from your model.
    Most of the time I use the controller so I will give you an example how you would do it from there. I also try to use your specific example, so you have something to work with.

    /app/controllers/people_controller.php
    
    function index() {
        //I like to write a separate array for fields and contain
        $fields = array(
            'name',
            'birthday',
            'gender'
        );
    
        /* It's important to know, that the fields will not get included into the
         * contain-array unless it's an associated model! */
        $contain = array(
            'Job' => array(
                //within another array you define the next level of contain
                'Branch' => array(
                    //you get the deal...
                    'City'
                ),
                //if you only need specific fields you can define this here like this:
                'fields' => array('title', 'date', 'salary'),
                //or order them directly!
                'order' => 'Job.salary DESC'
            )
        );
    
        //we now to our find-fall with our 2 arrays for the fields and the contain
        //every option (like fields or order) can be used in the containable
        $people = $this->Person->find('all', array('contain' => $contain, 'fields' => $fields));
    }
    

    I hope this helped you in understanding containable a little more.

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

Sidebar

Related Questions

Let me start out by saying I have tried this and looked at this
Let me start out by saying that I'm not a JavaScript developer so this
Let me start by saying that I do not advocate this approach, but I
Let me start by saying I'm a huge fan of the elegance of this
Let me start out by saying that I feel like there should be a
Let me start out by saying that I am new to Java/JSP web development,
Let me start by saying I know about position() but I can't seem to
Let me start out by saying I am no fan of tables but I
Let me start by saying this is associated with a homework assignment. However, this
This is my first post, so let me start by saying HELLO! I am

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.