我正在使用 Cakephp2.3
我有以下表格
表 1:用户
这里我有字段 group_id 和其他字段表 2:组表 3:学生
我在其中有字段 user_id
表 4:监护人
我在其中提交了 user_id
和 student_guardians
我有字段guardian_id、student_id 和relationship_id。
在其他表中,我们还有其他字段 firstname、lastname 等。
我用蛋糕烘焙来创建协会和
我想从学生/添加页面输入所有数据。像监护人(学生可以在一个表单上输入多个监护人并提交他的详细信息)
我创建了如下视图
<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>
在控制器功能中添加是
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.'));
}
}
}
它不保存任何数据
以上所有代码都已编写在 student_guradians 控制器中。
有没有人知道如何实现这个 var 数据转储
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" } } } }
谢谢