session.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 if (!class_exists('cakesession')) {
00039 uses('session');
00040 }
00041
00042 class SessionHelper extends CakeSession {
00043
00044
00045
00046
00047
00048 var $helpers = null;
00049
00050
00051
00052
00053
00054 var $__active = true;
00055
00056
00057
00058
00059
00060 function __construct($base = null) {
00061 if (Configure::read('Session.start') === true) {
00062 parent::__construct($base, false);
00063 } else {
00064 $this->__active = false;
00065 }
00066 }
00067
00068
00069
00070
00071
00072 function activate($base = null) {
00073 $this->__active = true;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 function read($name = null) {
00087 if ($this->__active === true && $this->__start()) {
00088 return parent::read($name);
00089 }
00090 return false;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 function check($name) {
00102 if ($this->__active === true && $this->__start()) {
00103 return parent::check($name);
00104 }
00105 return false;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115 function error() {
00116 if ($this->__active === true && $this->__start()) {
00117 return parent::error();
00118 }
00119 return false;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 function flash($key = 'flash') {
00132 if ($this->__active === true && $this->__start()) {
00133 if (parent::check('Message.' . $key)) {
00134 $flash = parent::read('Message.' . $key);
00135
00136 if ($flash['layout'] == 'default') {
00137 if (!empty($flash['params']['class'])) {
00138 $class = $flash['params']['class'];
00139 } else {
00140 $class = 'message';
00141 }
00142 $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
00143 } elseif ($flash['layout'] == '' || $flash['layout'] == null) {
00144 $out = $flash['message'];
00145 } else {
00146 $view =& ClassRegistry::getObject('view');
00147 list($tmpLayout, $tmpVars, $tmpTitle) = array($view->layout, $view->viewVars, $view->pageTitle);
00148 list($view->layout, $view->viewVars, $view->pageTitle) = array($flash['layout'], $flash['params'], '');
00149 $out = $view->renderLayout($flash['message']);
00150 list($view->layout, $view->viewVars, $view->pageTitle) = array($tmpLayout, $tmpVars, $tmpTitle);
00151 }
00152 echo($out);
00153 parent::del('Message.' . $key);
00154 return true;
00155 }
00156 }
00157 return false;
00158 }
00159
00160
00161
00162
00163
00164
00165 function valid() {
00166 if ($this->__active === true && $this->__start()) {
00167 return parent::valid();
00168 }
00169 }
00170
00171
00172
00173
00174
00175
00176
00177 function write() {
00178 trigger_error(__('You can not write to a Session from the view', true), E_USER_WARNING);
00179 }
00180
00181
00182
00183
00184
00185
00186 function id() {
00187 return parent::id();
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197 function __start() {
00198 if(!parent::started()) {
00199 parent::start();
00200 }
00201 return true;
00202 }
00203 }
00204 ?>