(私が思うに) 動作するカスタム セッション モデルを作成しました。アクション コントローラーには 2 つのテスト アクションがあります。
最初のアクションは次のとおりです。
public function testAction() {
$session = Mage::getSingleton('mymodule/session');
$session->func1('x');
$var1 = Mage::getSingleton('mymodule/session');
//Tracing through this function reveals that everything behaves as expected,
//$session is created, modified and then when $var1 is created, the same
//reference is returned and the two references refer to the same object
//($session === $var1) = true
}
2 番目のアクションは次のとおりです。
public function testresultAction() {
$session = Mage::getSingleton('mymodule/session');
var_dump($session);
//this method does not appear to work, and upon tracing through the
//getSingleton it is in fact creating a new session object, NOT returning
//the one that already existed.
}
私のセッションクラスは次のようになります。
class Mystuff_Mymodule_Model_Session extends Mage_Core_Model_Session_Abstract {
public function __construct() {
$namespace = 'Mystuff_Mymodule';
$this->init ( $namespace );
Mage::dispatchEvent ( 'mymodule_session_init', array (
'mymodule_session' => $this
) );
$this->setData('history', [] );
$this->setIndex ( - 1 );
}
public function func1($historyElement){
$history = $this->getData( 'history' );
array_unshift ( $history, $historyElement);
while ( count ( $history ) > 10 ) {
array_pop ( $history );
}
$this->setData ('history', $history);
$this->setIndex(-1);
}
}
また、他のポイントで testresultAction をちょうどに変更しましたが、そうするとvar_dump($_SESSION)
データが含まれているようです
SO、なぜ、私testAction()
を呼び出してシングルトンを作成し、データを編集すると、同時呼び出しでtestresultAction()
変更されたデータが存在せず、以前にインスタンス化されたシングルトンが取得されないのはなぜですか?