Anmeldungsfunktion in Benutzer-ControllerWie mache meine ich Session-Variablen zur Verfügung durch aus allen Controllern und Ansichten in CakePHP 3.2
public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
// print_r($user);
// die();
if ($user['role'] === 'student') {
$this->Auth->setUser($user);
$session = $this->request->session();
$session->write('user', $user);
return $this->redirect(['controller' => 'Useracountinfo/addinfo']);
} elseif .....
und meine Add Info-Funktion in der Useracountinfo
public function addinfo()
{
$this->loadModel('Users');
$userinfo= $this->Users->find('all');
$session = $this->request->session();
$userinfo = $session->read('user');
//print_r($userinfo);
//die();
$this->set($userinfo);
$user = $this->Useracountinfo->newEntity();
if ($this->request->is('post')) {
$user = $this->Useracountinfo->patchEntity($userinfo, $this->request->data);
print_r($user);
die();
if ($this->Useracountinfo->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('useracountinfo'));
$this->set('_serialize', ['useracountinfo']);
}`
und in Sehen Sie, ich habe so etwas
<?php echo '<strong>'.$userinfo['email'].'</strong>'; ?>
sind zu erreichen, was genau Ihr Problem? – arilia
Ich kann nicht auf die Sitzungsvariablen des Benutzers zugreifen Ich erhalte immer diesen Fehler Hinweis (8): Nicht definierte Variable: userinfo [APP/Template \ Useracountinfo \ addinfo.ctp, Zeile 198] –