大家好,我正在尝试创建一个表单,用户可以在其中创建一个新用户,该用户将具有与创建用户的人相同的 account_id。
目前我的页面在表单中显示了正确的 account_id,但是当我们将表单提交到数据库时,它保存为错误的东西。
这是我的功能
function add_Employee(){
$accounts=$this->User->find('list', array(
'fields'=>array('account_id'),
'conditions' => array(
'User.id' => $this->Auth->user('id'))));
if($this->request->is('post')){
$this->User->create();
if ($this->User->save($this->request->data))
{
$this->Session->setFlash('The user has been saved');
$this->redirect( array('controller'=>'Users','action' => 'index_admin'));
}
else { $this->Session->setFlash('The user could not be saved. Please, try again.'); }
}
$this->set('accounts',$accounts);
}
和视图
<h2>Add Employee</h2>
<p>Add a new Employee here, please enter their details below.</p>
<?php
echo $this->Form->create('User', array('action'=>'add_Employee'));
echo $this->Form->input('username',array('label'=>'Username: '));
echo $this->Form->input('password',array('label'=>'Password: '), array('type'=>'password'));
echo $this->Form->input('password_confirmation',array('label'=>'Confirm: '), array('type'=>'password'));
echo $this->Form->input('email',array('label'=>'Email: '));
echo $this->Form->input('title',array('label'=>'Title: '));
echo $this->Form->input('firstname',array('label'=>'First Name: '));
echo $this->Form->input('surname',array('label'=>'Surname: '));
echo $this->Form->input('active', array('default'=>true, 'type'=>'hidden'));
echo $this->Form->input('account_id', array('value'=>$accounts['User']['account_id']));
echo $this->Form->input('access_level', array(
'label' => 'Access Level:',
'options' => array('1'=>'Employee','2'=>'Adminstrator')));
echo $this->Form->end('Submit');
?>