simultaneously. For that purpose I use the following form:
echo $form->create('Robot', array('id' => 'RobotUploadForm', 'action'
=> '/upload'));?>
echo $form->input('name');
echo $form->input('description');
echo $form->input('Tag.all',array('type' => 'text', 'label' => 'Tags
(separate with comas)'));
echo $form->end('Submit');
and get the tags this way:
[Tag] => Array
(
[all] => tag1, tag2
)
In order to save all the tags at one shot, I rebuild $this->data to
look like this:
Array
(
[Robot] => Array
(
[name] => The name
[description] => The description
)
[Tag] => Array
(
[0] => Array
(
[Tag] => Array
(
[id] => tag1
)
)
[1] => Array
(
[Tag] => Array
(
[id] => tag2
)
)
)
)
But when I try to save, using $this->Robot->save($this->data), only de
robot's data is saved, despite the doc saying that Cake should save
the HABTM relation. Btw, all models and tables are properly modelized.
The upload function:
function upload() {
if (!empty($this->data)) {
debug($this->data);
$tags = split(',',$this->data['Tag']['all']);
$i=0;
foreach ($tags as $tag) {
$tag_array[$i]['id']=trim($tag);
$i++;
}
unset($this->data['Tag']['all']);
$this->data['Tag'] = $tag_array;
if ($this->Robot->save($this->data)) {
$this->Session->setFlash(__('The robot has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The robot could not be saved. Please,
try again.', true));
}
}
}
I'm sure there is a more elegant way to do this (or simply actually do
this). Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
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