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

  • Home
  • SEARCH
  • 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 6379375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:07:49+00:00 2026-05-25T02:07:49+00:00

The short version of this question is: How can I take data that only

  • 0

The short version of this question is:

How can I take data that only exists in an array (ie: not saved in a model yet) and relate it to a value in a $this->find('list') array from a model?

The long version of this question is:

I’m using CakePHP and the Wizard Component for a 3-step application form.

The 3 form steps are contact, course and details.

After these steps, there is a ‘review’ step which I want to display all of the submissions from the previous 3 form steps for the user to check one last time before pressing submit. For the most part, this works very well. I just need to do the following in the controller:

function _prepareReview() {
   $contact = $this->Wizard->read('contact');
   $course = $this->Wizard->read('course');
   $details = $this->Wizard->read('details');
   $this->set(compact('contact','course','details'));
}

Then, in review.ctp I can reference things like $contact['Contact']['firstname']; to get the person’s firstname etc.

However, the problem is getting data from ‘related’ models. For example, there’s a “Nationality” field which is just an ID. In the ‘details’ step, I use find('list') to get a list of all nationalities from the Nationality model as a dropdown menu which displays properly and then Cake saves the corresponding ID as it should do.

But, when I come to the ‘review’ step in the Wizard Component, I only get the actual ID from the Wizard Component’s array. I couldn’t really expect to get anything else.

I can’t see any obvious way to access $details[Detail][Nationality][name] (or something like this) from the context of the Wizard Component because setting recursive doesn’t work because the data isn’t actually in the model at this stage, it’s just an array of form data.

So, in other words, I have data in an array (NOT coming from a model, but from a form subsmission) as follows:

Array
(
   [Details] => Array
      (
         [firstname] => Test
         [nationality_id] => 3
      )
)

Then I have the following coming from a $this->Detail->Nationality->find('list') which looks like this:

Array
(
   [0] => American
   [1] => Australian
   [2] => British
   [3] => Canadian
)

So how can I get $details['Details']['nationality_id']; from the Wizard Component to display ‘Canadian’ instead of ‘3’ for example? How to I make the relationship when only one of the arrays is coming from a model? I only need this to momentarily confirm all of the data to the user. The id ‘3’ will, of course, be written to the Model once the user presses submit, and this is already working as it should do.

Or is this a completely crazy way of doing things and I should look at a totally different approach such as saving the data first? I don’t really want to save it until the user clicks the final submit, though.

  • 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-25T02:07:50+00:00Added an answer on May 25, 2026 at 2:07 am

    I can see what you are getting at here – CakePHP isn’t automatically querying these related models for you (as you aren’t pulling from the database) but you can’t help but think you are missing out on some of the framework’s free functionality.

    If you were still using FormHelper::input() it would automatically select the correct option (given you perform a Model::find('list') and passed the options list to the view first), but I’m assuming you wish for the review screen to be free of form inputs (disabled or not).

    The most straightforward approach would be to simply perform the same Model::find('list') calls you do for each step in the wizard, set the data from each to the view, and print out the appropriate value manually:

    // controller
    $nationalities = $this->Review->Details->Nationality->find('list');
    $this->set(compact(/*..., */ 'nationalities'));
    
    // view
    <?php echo $nationalities['Nationality'][$details['Detail']['nationality_id']]; ?>
    outputs 'Canadian' (the value for $nationalities['Nationality'][3])
    

    It might be possible to get CakePHP to do it for you by calling DboSource::queryAssociation() just right – if your up for the challenge – but is probably overkill for this particular problem.

    // model
    $db =& ConnectionManager::getDataSource($this->useDbConfig);
    $data = $db->queryAssociation($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet, $recursive, $stack) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The short version of the question - why can't I do this? I'm restricted
So the short version of this is: Can I traverse only the elements within
Inspired by this question . Short version: Why can't the compiler figure out the
This question is about a general technique in SQL, that I can't quite work
Hopefully short version of the question: If I'm on a machine that has a
Upon invsetigating 'mu is too short's answer to this question , I noticed that
Super-short version: I solved this problem when I was nearly finished writing the question.
Short version : echo testing | vim - | grep good This doesn't work
So the wonderful low down on this doozie of a problem: short version: We
Short version: assuming I don't want to keep the data for long, how do

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.