I am using Cakephp2.3
I have following tables
Table 1 : Users
Here i have field group_id and other fields
Table 2 :
Groups
Table 3 : Students
in which i have field user_id
Table 4 : Guardians
in which i have filed user_id
And student_guardians
where i have field guardian_id, student_id, and relationship_id.
and in others tables we have other fields firstname, lastname etc..
i used cake bake for creating associations and
i want to enter all data from students/add page. like guardians(student can able to enter multiple gurdians on single form submit with his details)
I created a view as following
<div class="guardianStudents form">
<?php echo $this->Form->create('GuardianStudent'); ?>
<fieldset>
<legend><?php echo __('Add Guardian Student'); ?></legend>
<?php
echo $this->Form->input('Student.first_name');
echo $this->Form->input('Guardian.0.Guardian.first_name');
echo $this->Form->input('Guardian.0.Guardian.last_name');
echo $this->Form->input('Guardian.0.User.username');
echo $this->Form->input('Guardian.0.User.password');
echo $this->Form->input('Guardian.0.User.group_id',array('type'=>'text','value'=>'1'));
echo $this->Form->input('Guardian.1.Guardian.last_name');
echo $this->Form->input('Guardian.1.Guardian.last_name');
echo $this->Form->input('Guardian.1.User.username');
echo $this->Form->input('Guardian.1.User.password');
echo $this->Form->input('Guardian.1.User.group_id',array('type'=>'text','value'=>'1'));
echo $this->Form->input('Student.User.group_id',array('type'=>'text','value'=>'1'));
echo $this->Form->input('Student.User.username');
echo $this->Form->input('Student.User.password');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Guardian Students'), array('action' => 'index')); ?></li>
<li><?php echo $this->Html->link(__('List Guardian Relationships'), array('controller' => 'guardian_relationships', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Guardian Relationship'), array('controller' => 'guardian_relationships', 'action' => 'add')); ?> </li>
<li><?php echo $this->Html->link(__('List Students'), array('controller' => 'students', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Students'), array('controller' => 'students', 'action' => 'add')); ?> </li>
<li><?php echo $this->Html->link(__('List Guardians'), array('controller' => 'guardians', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Guardian'), array('controller' => 'guardians', 'action' => 'add')); ?> </li>
</ul>
</div>
and in controller function add is
public function add() {
if ($this->request->is('post')) {
$this->GuardianStudent->create();
$this->loadModel('User');
if ($this->GuardianStudent->saveAll($this->request->data['Guardian'])) {
$this->Session->setFlash(__('The guardian student has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The guardian student could not be saved. Please, try again.'));
}
}
}
and it doesnot saving any data
All Above code has been writen in student_guradians controller ..
Does Any body have idea how to achieve this var dump of data
array(2) { ["Student"]=> array(2) { ["first_name"]=> string(5) "jkjkj" ["User"]=> array(3) { ["group_id"]=> string(1) "1" ["username"]=> string(10) "klklfkfkkl" ["password"]=> string(6) "lklklk" } } ["Guardian"]=> array(2) { [0]=> array(2) { ["Guardian"]=> array(2) { ["first_name"]=> string(5) "jkjkj" ["last_name"]=> string(8) "kjkjkjkj" } ["User"]=> array(4) { ["username"]=> string(7) "kjkjkjk" ["password"]=> string(7) "kjkjjkk" ["group_id"]=> string(1) "1" ["name"]=> string(1) "1" } } [1]=> array(2) { ["Guardian"]=> array(1) { ["last_name"]=> string(6) "jkkjkj" } ["User"]=> array(4) { ["username"]=> string(10) "jkljjljjkl" ["password"]=> string(6) "kjkjkj" ["group_id"]=> string(1) "1" ["name"]=> string(1) "1" } } } }
Thanks