0

我正在尝试遵循食谱中的约定,但没有运气。我烘焙了所有 CRUD 和模型关联,需要自定义管理员添加视图(管理员有 1 个用户)。当我尝试验证时,我收到了管理员模型的相应错误消息,但没有收到用户模型的错误消息。这是我用于表格的内容...

/* User Data */
echo __('<h3>Setup Login Information</h3>');
echo $this->Form->input('User.0.username');
echo $this->Form->input('User.0.password',  array('type'=>'password'));
echo $this->Form->input('User.0.password_confirm',  array('type'=>'password'));
echo $this->Form->input('User.0.user_role_id' );

/* Administrator Data */
echo __('<h3>User Information</h3>');
echo $this->Form->input('Administrator.first_name');
echo $this->Form->input('Administrator.last_name');
echo $this->Form->input('Administrator.title');
echo $this->Form->input('Administrator.email_address');
echo $this->Form->input('Administrator.phone_number');

这是我在控制器中设置的...

if( !empty($this->request->data) ) {
    // Use the following to avoid validation errors:
    unset($this->Administrator->User->validate['Administrator_id']);
    $this->Administrator->saveAssociated($this->request->data);
}

$users = $this->Administrator->User->find('list');
$userRoles = $this->User->UserRole->find('list');
$this->set(compact(array('users', 'userRoles')));
4

1 回答 1

2

如果管理员有 1 个用户,则无需在表单输入中指定索引:

echo $this->Form->input('User.0.username');
echo $this->Form->input('User.0.password',  array('type'=>'password'));
echo $this->Form->input('User.0.password_confirm',  array('type'=>'password'));
echo $this->Form->input('User.0.user_role_id' );

实际上应该是:

echo $this->Form->input('User.username');
echo $this->Form->input('User.password',  array('type'=>'password'));
echo $this->Form->input('User.password_confirm',  array('type'=>'password'));
echo $this->Form->input('User.user_role_id' );
于 2013-04-23T11:02:25.760 回答