Hi,

I'm new to CakePHP and actually I'm creating my first app with it. 
I'm trying to find out how to add a drop down list with the data of a column 
of another table. I mean, I have an add view for a students table, the 
students is related to a people table and people table is related to 
countries, I want to add the drop down list of countries to add a new 
student, but the student doesn't have direct relation to countries but does 
it have with people and people with countries. ¿What is the best way to do 
this? 
I'm using CakePHP 1.2

I could display a list of genders (geneders is related with the students 
table) with the following code:

Alumno = Student
Genero = Gender
Persona = Person

*In the add.ctp:*

echo $form->input('genero_id', array('empty' => '(choose one)', 'label' => 
'Gender'));

*In the student model:*

var $belongsTo = array(
'Genero' => array(
'className' => 'Genero',
'foreignKey' => 'genero_id'
),
'Persona' => array(
'className' => 'Persona',
'foreignKey' => 'persona_id'
),
);

*In the add function of student_controller:*

function add() {
// Se establece la lista de Generos,
// disponibles que se pueden seleccionar al crear un
// nuevo Alumno
$this->set('generos', $this->Alumno->Genero->find('list', array(
'fields' => array('Genero.abreviacionGenero')
)));

<https://lh6.googleusercontent.com/-wGCoj-xeuw8/Th1PMyv5FMI/AAAAAAAAAcE/3zj-QI_W0fE/s400/list.jpg>
Thanks!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to