0

I am trying to follow the conventions in the cookbook but am having no luck. I baked all of my CRUD and Model Associations and need to customize the Administrator Add View (Administrator Has 1 User). When I try and validate, I am getting the appropriate error messages for the Administrator model but not the User model. Here is what I am using for my form...

/* 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');

and here is what I have setup in the controller...

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')));
tereško
  • 58,060
  • 25
  • 98
  • 150
Randy Gonzalez
  • 445
  • 5
  • 17

1 Answers1

2

If administrator has 1 user, you do not need to specify an index on the form input:

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' );

Should actually be:

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' );
cowls
  • 24,013
  • 8
  • 48
  • 78