2015-10-23 58 views
1

我正在尝试为用户add创建一个日志系统,并在添加新用户时向管理员进行身份验证,要求他允许新用户登录。CakePHP 3.0将数据保存到表中

任何人都知道是否有插件可用?或者我怎样才能将这些数据保存在两个表格中。

我已经试过这

public function add() { 
    $user = $this->Users->newEntity(); 
    $log = $this->Logs->newEntity(); 
    if ($this->request->is('post')) { 
    $user = $this->Users->patchEntity($user, $this->request->data); 
    $user->criado_por = $this->Auth->user('nome'); 
    $user->modificado_por = $this->Auth->user('nome'); 
    $user->userstatus = 'waiting for permitions'; 

    $log->date = date::now(); 
    $log->newuser = $user->name; 
    $log->whocreate = $this->Auth->User('name'); 

    if ($this->Users->save($user)) { 
     $this->Flash->success(__('The user has been saved.')); 
     return $this->redirect(['action' => 'index']); 
    } else { 
     $this->Flash->error(__('The user could not be saved. Please, try again.')); 
    } 
    } 
    $this->set(compact('user')); 
    $this->set('_serialize', ['user']); 
} 

回答