Both the fields in the form are multi-select, so how you want to save the data? Will all selected users relate to all selected exercises?
Amit Badkas
PHP Applications for E-Biz: http://www.sanisoft.com
On Fri, Jan 28, 2011 at 4:07 AM, cake bake <cake.bakerr@gmail.com> wrote:
is there any way to save multiple related records here is my code
function asign() {
$this->loadModel('UsersExercise');
if (!empty($this->data)) {
$this->UsersExercise->create();
if ($this->UsersExercise->save($this->data)) {
$this->Session->setFlash(__('The exercise could not be saved.
Please, try again.', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The exercise could not be saved.
Please, try again.', true));
}
}
$users = $this->Exercise->User->find('list');
$exercises = $this->Exercise->find('list');
$this->set(compact('users'));
$this->set(compact('exercises'));
}
<?php echo $this->Form->create('UsersExercise',array('url' => '/
exercises/asign'));?>
<fieldset>
<legend><?php __('Add Exercise'); ?></legend>
<?php
echo $this->Form->input('user_id',array('type' =>
'select','multiple' => true,'options' => $users) );
echo $this->Form->input('exercise_id',array('type' =>
'select','multiple' => true,'options' => $exercises) );
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
here is the debug for this->data
Array
(
[_Token] => Array
(
[key] => 3sss
[fields] => sss )
[UsersExercise] => Array
(
[user_id] => Array
(
[0] => 1
)
[exercise_id] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
)
)
--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment