我有一个User
模型belongsTo
与Profile
现在,每当我想创建一个用户时,我也想创建我的个人资料。
为此,我创建了以下表格:
<div class="span9" id="lejer">
<?php echo $this->Form->create('User', array('class' => 'form-horizontal')); ?>
<?php echo $this->Form->input('group_id', array('type' => 'hidden', 'value' => 3));?>
<h3 class="heading3">Dine Personlige Informationer:</h3>
<div class="registerbox">
<fieldset>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
Fornavn:
</label>
<div class="controls">
<?php echo$this->Form->input('Fornavn', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
Efternavn:
</label>
<div class="controls">
<?php echo$this->Form->input('Efternavn', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
Telefon:
</label>
<div class="controls">
<?php echo$this->Form->input('Telefon', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
E-mail:
</label>
<div class="controls">
<?php echo$this->Form->input('E-mail', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
</fieldset>
</div>
<h3 class="heading3">Your Address</h3>
<div class="registerbox">
<fieldset>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
Addresse:
</label>
<div class="controls">
<?php echo$this->Form->input('Addresse', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
Postnr:
</label>
<div class="controls">
<?php echo$this->Form->input('Postnr', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
By:
</label>
<div class="controls">
<?php echo$this->Form->input('By', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="red">*</span>
Område:
</label>
<div class="controls">
<?php echo$this->Form->input('Område', array('class'=> 'input-xlarge', 'label' => '')); ?>
</div>
</div>
</fieldset>
</div>
现在,当我调试时,我可以看到所有数据都在以下范围内array
:
$this->request->data['User'];
现在在我的 UsersController 中,我有以下create
操作:
public function create() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->saveAll($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}
但是当我运行它时,只User
创建 a 而不是 a Profile
。
谁能告诉我我做错了什么?我认为saveAll
我会保存到它的关系模型中。