我有我的控制登錄操作。會話是爲Auth.User創建的,但不適用於Auth.Town。我需要創建會話。我在城鎮桌上有幾個字段,我不想創建50行。我怎樣才能讓它更容易?我需要簡化它。如何簡化我爲鏈接的模型創建的新會話?
UsersController:
public function login() {
if ($this->request->is('post')) {
if (isset($this->request->data['UserLogin'])) {
$this->request->data['User'] = $this->request->data['UserLogin'];
}
if ($this->Auth->login()) {
$this->Session->write(
'Auth.Town.name',
$this->User->Town->field('name')
);
$this->Session->write(
'Auth.Town.country',
$this->User->Town->field('country')
);
$this->Session->write(
'Auth.Town.localisation',
$this->User->Town->field('localisation')
);
$this->Session->write(
'Auth.Town.statut',
$this->User->Town->field('statut')
);
return $this->redirect($this->Auth->redirect());
}else{
$this->Session->setFlash("L'adresse électronique ou votre mot de passe ne correspond pas","notif",array('type'=>'error'));
}
}
}
uhhmmmmm。循環? – Ghost 2014-09-22 12:08:01
請始終提及您的確切CakePHP版本! – ndm 2014-09-22 13:32:00