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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:20:35+00:00 2026-05-25T13:20:35+00:00

I have built a CakePHP app that creates appointments which have both a client

  • 0

I have built a CakePHP app that creates appointments which have both a client and a doctor assigned to them from other tables in the database.

On the appointment add screen I want to be able to choose the Doctor name from a drop down (note the name consists of two fields, firstname and lastname and their is also a field called title for the prefix e.g. Mr). The information it SHOULD save though is the doctor_id as that is how the two tables are linked!

I have added the following to my view:

<?php echo $this->Form->input('doctor_id',array('label'=>'<strong>Choose Doctor</strong>'),$doctors); ?>

and then in my controller:

$this->set('doctors', $this->Appointment->Doctor->find('list'));

However this creates a list of random elements from the database. How can I get this to work? So the dropdown produced is something like:

<select>
<option value="1">Mr. John Doe</option>
<option value="2">Mrs. Jane Doe</option>
</select>
  • 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-25T13:20:36+00:00Added an answer on May 25, 2026 at 1:20 pm

    You can specify the fields you want to show in the drop down list by adding a ‘fields’ parameter to the find(), and you can use a virtualField in your Doctor model to get a name (or fullname).

    doctor.php:

    public function __construct($id = false, $table = null, $ds = null) {
        parent::__construct($id, $table, $ds);
    
        // This is for MySQL, change for whatever DB flavour you're using.
        $this->virtualFields = array(
          'name' => "CONCAT(`{$this->alias}`.`prefix`, ' ', `{$this->alias}`.`firstname`, ' ', `{$this->alias}`.`lastname`)"
      );
    }
    

    Change your find(‘list’) in your controller to:

    $this->set('doctors', $this->Appointment->Doctor->find(
      'list',
      array(
        'fields' => array('Doctor.name')
      )
    );
    

    You can of course add a ‘order’ parameter…

    $this->set('doctors', $this->Appointment->Doctor->find(
      'list',
      array(
        'fields' => array('Doctor.name'),
        'order' => array('Doctor.firstname', 'Doctor.lastname')
      )
    );
    

    Hope that helps.

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

Sidebar

Related Questions

I have built a CakePHP app for creating appointments against clients and everytime I
I have built a cakephp app that needs the user to login or register(for
I have built an application in CakePHP that lists businesses. There are about 2000
I have built and app which does random stuff and I want to collect
This site is built using CakePHP 1.2* I have an element that needs to
I am currently trying to build a cakephp app that will list items from
I have a site (built on LAMP (cakephp) and has ssl certificate installed) which
I have a cakePhp application built, and now I'm creating a simple blog based
I have built an MSI that I would like to deploy, and update frequently.
I have built a simple C#.Net app on a M/C with only .Net FX

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.