我只是在處理新項目的用戶管理組件。 該計劃是:在網頁CakePHP 2.0帳戶激活後自動登錄
- 用戶註冊到帳戶數據的最小量的(用戶名,通過電子郵件)
- 用戶得到一個電子郵件與激活鏈接激活
- 用戶點擊該帳戶鏈接和激活他的帳戶
- 在用戶的系統日誌激活後後會自動重定向和他那種與帳戶信息的儀表盤(最後一次登錄,喜「用戶名」等)
但是自動登錄有一些問題。這是我使用的代碼部分:
<?php
...
// set userstatus to "active" and delete meta information "activation_key"
// then automatically login
$this->User->id = $id;
$this->User->saveField('modified', date('Y-m-d H:i:s'));
$this->User->saveField('status', 1);
// $this->User->deleteActivationKey ....
$this->Auth->login($this->User->read());
$this->Session->setFlash(__('Successfully activated account. You are now logged in.'));
$this->User->saveField('last_login', date('Y-m-d H:i:s'));
$this->redirect(array('controller' => 'pages'));
...
到目前爲止是這種情況,直到你想獲得登錄的用戶與驗證組件的用戶()函數的信息。
我們在AppController-> beforeRender用這個,有廣泛的用戶信息應用:
$this->set('auth', $this->Auth->user());
但自動登錄操作後,我得到未定義指數告示。 (例如通過訪問視圖中的$ auth ['id'])。 print_r()只顯示當前用戶的用戶名和哈希密碼。 如果您手動登錄,一切工作正常。它必須是在帳戶激活後自動登錄的東西。
似乎是會話的問題?我究竟做錯了什麼?
您可以使用: $ this-> Auth-> login($ user ['User']); – 2012-04-13 21:28:05