|
<?php |
|
|
|
class IndexController extends Zend_Controller_Action |
|
{ |
|
public function indexAction() |
|
{ |
|
switch ($this->_getParam('what', 'test')) { |
|
case 'store': $this->_store(); break; |
|
case 'retrieve': $this->_retrieve(); break; |
|
case 'clear': $this->_clear(); break; |
|
case 'test': |
|
default: $this->_test(); break; |
|
} |
|
|
|
echo '<hr />'; |
|
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'test')) . '">Test object (no session)</a> | '; |
|
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'store')) . '">Store (Note: clear before storing again)</a> | '; |
|
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'retrieve')) . '">Retrieve</a> | '; |
|
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'clear')) . '">Clear</a>'; |
|
} |
|
|
|
protected function _getSubject() |
|
{ |
|
$s = new Application_Model_SleepingModel(); |
|
$s->aMember = 'foo'; |
|
$s->anotherMember = 'bar'; |
|
return $s; |
|
} |
|
|
|
protected function _test() |
|
{ |
|
$subject = $this->_getSubject(); |
|
echo 'My test subject:'; |
|
var_dump($subject); |
|
|
|
echo 'Serialize:'; |
|
$subject_ser = serialize($subject); |
|
var_dump($subject_ser); |
|
|
|
echo 'Wake-up :'; |
|
$o2 = unserialize($subject_ser); |
|
var_dump($o2); |
|
} |
|
|
|
protected function _store() |
|
{ |
|
echo '(please clear before storing again)<br />'; |
|
$subject = $this->_getSubject(); |
|
$subject->anotherMember = 'baz'; |
|
echo 'My test subject:'; |
|
var_dump($subject); |
|
|
|
echo 'Storing in session...'; |
|
$session = new Zend_Session_Namespace('testingSleepingModel'); |
|
$session->mySleeper = $subject; |
|
echo '... done'; |
|
} |
|
|
|
protected function _retrieve() |
|
{ |
|
echo 'Fetching from session...'; |
|
$session = new Zend_Session_Namespace('testingSleepingModel'); |
|
var_dump($session->mySleeper); |
|
echo '... done'; |
|
} |
|
|
|
protected function _clear() |
|
{ |
|
@Zend_Session::destroy(true, false); |
|
} |
|
} |