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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:47:23+00:00 2026-06-03T19:47:23+00:00

I want to place fields from a model in a select list. I have

  • 0

I want to place fields from a model in a select list.
I have this code..

brand.php & car.php models

 class Brand extends AppModel{ 
  var $name = 'Brand'; 
  var $hasMany = 'Car'; 
 }
 <?php   
 class Car extends AppModel{ 
  var $name = 'Car'; 
  var $belongsTo = 'Brand'; 
 } 
 ?>

the controller

   <?php 
   class CarsController extends AppController{
   var $name = 'Cars';
   function index(){
   $this->set('id', $this->Car->find('all'));
   }
   }
  ?>

this is the view index.ctp

<?php   
echo $form->create('Search'); 
foreach($id as $options){ 
     echo $options['Brand']['name']."<br>";  // it works
$values = array(); 
$values[] = $options['Brand']['name']; // doesnt work!

} 
echo $this->Form->select('one', $values); // the values for selects just the last one
echo $form->end('search'); 
?>

So how place the fields and id for the option values from the Brand.php model in the select list??

  • 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-03T19:47:25+00:00Added an answer on June 3, 2026 at 7:47 pm

    In your controller:

    $this->set('brands', $this->Car->Brand->find('list'));
    

    In your view:

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

    Cake will automagically link the $brands view var to the brand_id fields options list.

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

Sidebar

Related Questions

So I have a few Django models that look like this: class City(models.Model): name
I want to inherit a model class from some 3rd party code. I won't
I want to place UItextField in UITableViewCell but I have problem. Text field don't
I want to place a table on my page. I have two tables in
I have a list that contain two colums which are type currency. I want
First off, I have read through a list of postings on this topic and
i have this thing in my models.py file user = models.ForeignKey('auth.User', unique = True)
This time I have problem with virtual fields. I have core class for my
I am having a problem getting a list of fields from a query defined
In my document I have this script: $.ajax({ type:POST,url:ajax.php,data:data, success: function() { //onsuccess },

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.