【发布时间】:2013-03-02 05:34:09
【问题描述】:
我正在使用 Cakephp2.3
我有以下表格
表 1:用户
这里我有字段 group_id 和其他字段
表 2:
团体
表 3:学生
我有字段 user_id
表 4:监护人
我在其中提交了 user_id
还有学生监护人
我有字段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" } } } }
谢谢
【问题讨论】:
-
到底是哪个错误,你能说一下吗?或者您是否通过调试级别 2 进行了检查?还有一个原因可能是您在模型关联中提到的关系..检查少量数据而不是一目了然...
-
试试
$this->GuardianStudent->saveAll($this->request->data)这对你有用。另外,如果你能告诉我们var_dump($this->request->data)。 -
我正在检查少量数据。没有这样的错误。它只是显示无法保存。调试级别已经是 2
-
@Rikesh:使用 var 数据转储编辑的问题
标签: php cakephp cakephp-2.0 cakephp-model