So you have your view with some fields in it, including your forign key -
here assuming farm_id
views/fields/add.ctp
<?php echo $form->create('Field')?>
<?php echo $form->input('name')?>
<?php echo $form->input('another')?>
<?php echo $form->input('yet_another')?>
<?php echo $form->input('farm_id')?>
<?php echo $form->end('Submit')?>
And in your controller action add ( as long as you have your association set
up correctly which we'll assume you do as you mention it)
controllers/fields_controller.php
function add(){
~~~~~
$this->set('farms', $this->Field->Farm->find('list'));
}
This will set values to your view that the form helper will automatically
pick up and set as the values of your Field.farm_id input - which will
become a select.
-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Travis
Sent: Saturday, 4 July 2009 3:34 a.m.
To: CakePHP
Subject: Forms with multiple tables
I am new to cakePHP and am in the process of learning to use it.
I am wondering how I can have a form element populated with elements
from a different table than the model, for example
I am wanting to write a farm manager using cakePHP as the framework,
if I have fields that belong to farms, when you create a new field I
want to be able to select from a list of farms, and have it link
(insert farm's id as a foreign key), I have currently setup my
belongsto relationship so I can view but I cannot add.
my original thought was to create a $options array and just loop
through the table, but I cannot do that if I do not have access to the
farms table.
Help!
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4214 (20090703) __________
The message was checked by ESET NOD32 Antivirus.
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4215 (20090704) __________
The message was checked by ESET NOD32 Antivirus.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment