it looks like i didn't explain right:
Please have a new more complete explanation
*I have 2 tables: users and users_details.
UsersDetail Model:*
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
);
*Users Model:*
public $hasOne = array(
'UsersDetail' => array(
'className' => 'UsersDetail',
//'joinTable' => 'users_detail',
'foreignKey' => 'user_id',
),
);
*the edit method:*
public function account_edit($id = null){
if (!$this->User->exists($id)) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->User->saveAll($this->request->data)) {
$this->Session->setFlash(__('The user has been updated.'));
return $this->redirect(array('action' => 'account'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try
again.'));
}
} else {
$options = array('conditions' => array('User.' . $this->User->primaryKey
=> $id));
$this->request->data = $this->User->find('first', $options);
$this->set('photo', $this->request->data['User']['photo']);
}
}
*edit ctp:*
echo $this->Form->create('User', array('type' => 'file'));
<legend><?php echo __('Edit User'); ?></legend>
echo $this->Form->input('UsersDetail.facebook');
echo $this->Form->input('UsersDetail.user_id', array('type'
=> 'hidden'));
echo $this->Form->input('User.id');
echo $this->Form->input('User.password');
echo $this->Form->input('User.nume');
etc..
echo $this->Form->input('User.birthday', array(
'label' => 'Data Nasterii',
'dateFormat' => 'DMY',
'minYear' => date('Y') - 70,
'maxYear' => date('Y') - 18,
));
echo $this->Form->input('User.photo', array('type' =>
'file'));
echo $this->Form->end(__('Submit'));
*When i save the edit i receve*
*
Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
'91' for key 'PRIMARY'
*
*also the print_r off all $this->request->data() is:*
Array
(
[UsersDetail] => Array
(
[facebook] => essteffand
[user_id] => 91
)
[User] => Array
(
[id] => 91
[password] => pass
[nume] => name
)
)
--
View this message in context: http://cakephp.1045679.n5.nabble.com/Use-2-tables-for-update-tp5718641p5718700.html
Sent from the CakePHP mailing list archive at Nabble.com.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Tuesday, July 1, 2014
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment