我使用Cakephp2.3cakePHP2.3保存所有
我有以下各表
表1:用户
这里我有场GROUP_ID等领域 表2: 组 表3:学生
在我所字段USER_ID
表4:监护人
在我所提交user_id说明
而且student_guardians
其中i有场guardian_id,student_id数据,和relationship_id。
,而在其他表我们已经等领域名字,姓氏等。
我用蛋糕烘烤制作协会和
我想从学生进入所有数据/添加页面。像监护人(学生可以能够进入单的形式与他的详细资料提交多个gurdians)
我创建的视图如下
<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控制器中。
是否有任何身体有想法如何实现这种数据 变种转储
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" } } } }
感谢
究竟哪个错误即将到来您可以放下吗?还是通过调试级别2进行检查?还有一个原因可能是你在模型关联中提到的关系..使用少量数据检查而不是一目了然检查一个... – Jhanvi 2013-03-02 05:45:00
尝试'$ this-> GuardianStudent-> saveAll($ this-> request->数据)'这将为你工作。另外,如果你能向我们展示var_dump($ this-> request-> data)'。 – Rikesh 2013-03-02 05:52:38
我正在检查少量数据。没有这样的错误。它只是显示无法保存。调试级别已经是2 – Rashmi 2013-03-02 05:53:13