I am looking for some help on prepopulating a select form helper and
setting a default selected value using Cake1.2. I have seen solutions
but they are all in Cake1.1 Any help would be greatly appreciated!
Here is what I have so far:
Controller code:
--------------------------------------------------------------
function edit($id = null)
{
//ensure user has logged in
$this->checkSession();
$this->ProjectUpdate->id = $id;
if (empty($this->data)) {
$this->data = $this->ProjectUpdate->read();
// **** Using this to populate the select form helper *******
$projectNames = $this->ProjectUpdate->Project->find('list', array
('fields' => 'Project.name', 'order' => 'Project.name ASC'));
$this->set('projectNames', $projectNames);
}
else {
if ($this->ProjectUpdate->save($this->data)) {
$this->Session->setFlash('Your project has been updated.');
$this->redirect(array('action' => 'index/1'));
}
}
}
View code
---------------------------------------------------
echo $form->select('Project.id', $projectNames, null, null, false);
Thanks guys I appreciate the assistance!
Chris
--~--~---------~--~----~------------~-------~--~----~
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