here is working code from my app:
Controller Code:
public function add() {
if ($this->request->is('post')) {
$this->Member->create();
if ($this->Member->User->saveAll($this->request->data)) {
$this->Session->setFlash(__('The member has been saved.'));
return $this->redirect($this->referer());
} else {
$this->Session->setFlash(__('The member could not be saved. Please, try again.'), 'flash_message_error');
}
}
$countries = $this->Member->Country->fetchList();
$title_for_layout = 'Membership Signup';
$this->set(compact('title_for_layout', 'countries'));
}
User Model Code:
public $hasOne = 'Member';
Member Model Code:
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
View Code:
<div class="row">
<?php echo $this->Form->create('Member', array('url'=>array('controller'=>'members', 'action'=>'add', 'admin'=>false))); ?>
<div class="col-md-12 col-sm-12 col-xs-12">
<h3 class="sign-head">Personal Information</h3>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<?php echo $this->Form->input('User.username', array('div'=>FALSE, 'required'=>TRUE, 'placeholder'=>'username')); ?>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<?php echo $this->Form->input('User.password', array('div'=>FALSE, 'required'=>TRUE, 'placeholder'=>'Password')); ?>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<?php echo $this->Form->input('Member.first_name', array('div'=>FALSE, 'required'=>TRUE, 'placeholder'=>'Name')); ?>
</div>
<div class="col-md-12 col-sm-6 col-xs-12">
<?php echo $this->Form->submit('submit', array('div'=>FALSE, 'class'=>' submit-contact')); ?>
</div>
<?php echo $this->Form->end(); ?>
</div>
Hope this help to other user.