「ユーザーをログインしなおしたい」
って時ありませんか?
例えばDBの内容を更新した歳に、Sessionの内容も同時に更新。
それをDBの内容を更新したら自動的にSessionの内容も更新できればいいのに・・・ナンテ。
そんな関数を作ってみました。
○Authコンポーネントの適当な行に追加
function reflesh()
{
$this->__setDefaults();
$session = $this->Session->read($this->sessionKey);
$this->{$this->userModel} = Classregistry::init($this->userModel);
$res = $this->{$this->userModel}->find('first',array('conditions' => array('id' => $session['id'] ,$this->fields['username'] => $session[$this->fields['username']])));
unset($res[$this->userModel][$this->fields['password']]);
$this->Session->delete($this->sessionKey);
$this->Session->write($this->sessionKey,$res[$this->userModel]);
}
で、ユーザーがログイン中、適当なコントローラーで
$this->Auth->reflesh();
とやるとDBの最新の内容がSessionに格納される。



