Controller / UsersController.php
<?php
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
/* allow add action so user can register */
$this->Auth->allow('add');
}
public function login() {
if ($this->request->is('post')) {
/* login and redirect to url set in app controller */
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
public function logout() {
/* logout and redirect to url set in app controller */
return $this->redirect($this->Auth->logout());
}
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
//
// If the user was saved, Now we add this information to the data
// and save the Profile.
$this->Session->setFlash(__('The user has been saved'));
return $this->redirect(array('controller' => 'pages','action' => 'home'));
}
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}
//
?>
这里我添加了一个表格配置文件(当用户在 function add()中创建用户时,在表格中插入Userid) 为此我改变了更多,所以最终我找到了解决方案所以请指导我
答案 0 :(得分:1)
在用户保存数据时,您可能需要加载配置文件模型。
if ($this->User->save($this->request->data)) {
$this->loadModel('Profile'); // it may be different as per your table
$this->Profile->saveField('field_name', 'value');
希望它会帮助你