43 lines
877 B
PHP
43 lines
877 B
PHP
<?php
|
|
|
|
/**
|
|
* http://www.alternateinterior.com/2006/09/a-viewstate-for-php.html
|
|
* Управление состоянием между страницами
|
|
*/
|
|
class ViewState // extends Collection
|
|
{
|
|
private $values = array();
|
|
|
|
function set($name, $value)
|
|
{
|
|
$this->values[$name] = $value;
|
|
}
|
|
|
|
function get()
|
|
{
|
|
$args = func_get_args();
|
|
$result = $this->values;
|
|
foreach ($args as $name) {
|
|
if (!isset($result[$name])) {
|
|
return null;
|
|
}
|
|
$result = $result[$name];
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
function saveState()
|
|
{
|
|
return base64_encode(serialize($this->values));
|
|
}
|
|
|
|
function restoreState($value)
|
|
{
|
|
$this->values = unserialize(base64_decode($value));
|
|
}
|
|
|
|
function export()
|
|
{
|
|
return $this->values;
|
|
}
|
|
}
|