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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:50:26+00:00 2026-06-01T19:50:26+00:00

i am cakephp beginner. My Employee Model, class Employee extends AppModel { var $belongsTo

  • 0

i am cakephp beginner.

My Employee Model,

         class Employee extends AppModel {
            var $belongsTo = array(
                'Department'=>array(
                'className'=>'Department',
                'foreignKey'=>'department_id',
                'conditions'=>null,
                'fields'=>null
               )
         );
          blah--

now in employee add.ctp i want to create a select box which list all the department.
i was going through official cakephp 2.1 documentation (here)
it tells me to add

  $this->set('departments', $this->Employee->Department->find('list')); 

in my controller..

i have no idea to put in which controller ? is it in EmployeesController or DepartmentsController? and in which action of controller?

view to create select box (in add.ctp)

         echo $this->Form->input('Department');
  • 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-01T19:50:28+00:00Added an answer on June 1, 2026 at 7:50 pm

    you were almost correct – only a minor glitch:

    echo $this->Form->input('department_id');
    

    you need to name the fields as they are in the database.
    and if it is a BelongsTo relation than there should be a department_id foreign key in your employees table.

    PS: cake knows that if you pass down $departments that this array will need to be the options for this form field. so no additional configuration necessary!

    // in your add action at the very bottom
    $departments = $this->Employee->Department->find('list');
    $this->set(compact('departments')); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CakePHP problems by not getting the _schema my model in cakephp: <?php App::uses('AppModel', 'Model');
In cakephp, I used $rNo array in WHERE clause. $rooms =$this->find('all',array( 'conditions'=>array(NOT=>array('Room.id'=>$rNo)), 'group'=>array('Room.room_type_id'))); Now,
I am just a newbie in cakephp and struggled a lot as a beginner,
I have the CakePHP stack in /var/www/site from one view under controller A I
i'm still a beginner, and guess it's a simple CakePHP question... all i want
I'm facing this problem as a CAKEPHP beginner, sorry if this is a very
i am beginner in cakephp , and i want use SQL IN operator in
i'm beginner in cakephp,i don't know how to get the tags name in xml
i am beginner in cakephp and i need to correct and sample code for
i am beginner in cakephp and i need simple template in cakephp . i

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.