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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:42:58+00:00 2026-05-18T22:42:58+00:00

I think i’ve missed something. (cakephp) I have a hasMany relationship from applicants to

  • 0

I think i’ve missed something. (cakephp)

I have a hasMany relationship from applicants to employers.And when i view an applicant, i see the related employers table all working perfectly (thanks to bake!)

But if i click ‘New Employer’, i want the applicants dropdown to pre-select so that i can hide it. i just cant figure out how i’d pass the applicant_id to the add view for employers.

(if i edit an employer from the related employers table for an applicant, the applicant_id does get passed)

Can anyone help? please?
Vauneen

  • 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-18T22:42:59+00:00Added an answer on May 18, 2026 at 10:42 pm

    Simple. Pass the applicant_id to your employers/add action.

    One way to do this is through URL parameters. Example: /employers/add/3 will pass “3” to the add action, and this could be taken as the applicant ID. Here’s the controller code:

    function add($applicantId = null) {
        // Optional: Check if $applicantId is provided
        if (!$applicantId) {
            $this->Session->setFlash('Applicant ID is missing.');
            $this->redirect(array('action' => 'index'));
        }
        // Process action
        if (!empty($this->data)) {
            $this->Employer->create();
            if ($this->Employer->save($this->data)) {
                // etc ...
            }
        } else {
            // Insert default values such as applicant_id into the form
            $this->data = array(
                'Employer' => array(
                    'applicant_id' => $applicantId
                )
           );
        }
    }
    

    Now, you need to ensure that all links provide the applicant ID parameter:

    echo $this->Html->link('Add Employer', array('controller' => 'employers', 'action' => 'add', 3);
    

    (Note: The last element “3” is the applicant ID)

    Finally, you can hide the applicant ID from the form in the add.ctp file:

    echo $this->Form->input('applicant_id', array('type' => 'hidden'));
    

    Hope that helps!

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

Sidebar

Related Questions

I think I have run into a bug in Mojarra 2.1.0. Maybe I missed
I have a bunch of posts stored in text files formatted in yaml/textile (from
Think of this: A view controller's view is added as subview to another view.
Think Windows Explorer's 'Details' view. I need to output my database to this view.
Think Design: I have many applications that share the same user database! Other tables
think about having a skript where you have some words as input. now you
Think 2 entities OneToOne mapped. Person and Car. A Person can have a Car.
I think that I am having a slow evening but I have a question
I think I just need someone to show me the obvious. I have a
I think this is not really possible but worth asking anyway. Say I have

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.