Core Session:- Mage::getSingleton(‘core/session’)
Customer Session:- Mage::getSingleton(‘customer/session’)
Admin Session:- Mage::getSingleton(‘adminhtml/session’)
Customer Session:- Mage::getSingleton(‘customer/session’)
Admin Session:- Mage::getSingleton(‘adminhtml/session’)
Supponiamo di voler settare la variabile di sessione: ‘testing_magento‘.
Si imposta direttamente con il metodo anche se non esiste:
Mage::getSingleton(‘core/session’)->setTestingMagento(‘hello’);
Recuperare nello stesso modo:
$test = Mage::getSingleton(‘core/session’)->getTestingMagento();
Ed eliminare
Mage::getSingleton(‘core/session’)->setTestingMagento();
Eventualmente è possibile impostare, recuperare, testate e cancellare la variabile di sessione con:
- setData('<nome variabile>', <valore>)
- getData('<nome variabile>', <valore>)
- hasData('<nome variabile>') --> boolean
- unsetData('<nome variabile>')
- unsetOldData('<nome variabile>') <-- mai usato
Come fa Magento a determinare il nome del metodo set e get da 'testing_magento', ossia da Mage::getSingleton(‘core/session’)->setData( 'testing_magento',‘hello’) a Mage::getSingleton(‘core/session’)->setTestingMagento(‘hello’)?
File: Varien/Object.php
1° step chiamata al magic method __call(.....)
2° step chiamata a _underscore
/**
* Converts field names for setters and geters
*
* $this->setMyField($value) === $this->setData('my_field', $value)
* Uses cache to eliminate unneccessary preg_replace
*
* @param string $name
* @return string
*/
protected function _underscore($name)
{
if (isset(self::$_underscoreCache[$name])) {
return self::$_underscoreCache[$name];
}
$result = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $name));
self::$_underscoreCache[$name] = $result;
return $result;
}
Commenti
Posta un commento