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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:10:31+00:00 2026-06-05T13:10:31+00:00

I thought this would be a relatively common thing to do, but I can’t

  • 0

I thought this would be a relatively common thing to do, but I can’t find examples anywhere, and the Cookbook’s section on find() was not clear in the slightest on the subject. Maybe it’s just something that’s so simple Cake assumes you can just do it on your own.

All I’m looking to do here is retrieve a User’s name (not the currently logged-in user…a different one) in Cake based on their ID passed to my by an array in the view.

Here’s what I’ve got in the controller:

public function user_lookup($userID){
  $this->User->flatten = false;
  $this->User->recursive = 1;
  $user = $this->User->find('first', array('conditions' => $userID));
  //what now?
}

At this point, I don’t even know if I’m on the right track…I assume this will return an array with the User’s data, but how do I handle those results? How do I know what the array’s gonna look like? Do I just return($cakeArray['first'].' '.$cakeArray['last'])? I dunno…

Help?

  • 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-05T13:10:32+00:00Added an answer on June 5, 2026 at 1:10 pm

    You need to use set to take the returned data, and make it accessible as a variable in your views. set is the main way you send data from your controller to your view.

    public function user_lookup($userID){
      $this->User->flatten = false;
      $this->User->recursive = 1;
    
      // added - minor improvement
      if(!$this->User->exists($userID)) {
          $this->redirect(array('action'=>'some_place')); 
          // the requested user doesn't exist; redirect or throw a 404 etc.
      }
    
      // we use $this->set() to store the data returned. 
      // It will be accessible in your view in a variable called `user` 
      // (or what ever you pass as the first parameter)
      $this->set('user', $this->User->find('first', array('conditions' => $userID)));
    
    }
    
    
    // user_lookup.ctp - output the `user`
    <?php echo $user['User']['username']; // eg ?>
    <?php debug($user); // see what's acutally been returned ?>
    

    more in the manual (this is fundamental cake stuff so might be worth having a good read)

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

Sidebar

Related Questions

I thought this would be a common question, but I didn't find it anywhere...
I thought I would find a solution to this problem relatively easily, but here
Okay at first I thought this would be pretty straightforward. But I can't think
I thought this would be relatively easy but running it, gives wrong result. It
I thought this would be a relatively simple task with something like FMOD, but
Thought this would be pretty straight forward, but my value is remaining the same
I thought this would be a simple task but i cannot figure out why
I thought this would be fairly easy, but I'm totally baffled. I want one
I thought this would be pretty easy but I'm running into all sorts of
OK so I thought this would be pretty simple but it's tripping me up..

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.