初学 Phreeze 4

在项目中我们时常会用到session,可是在phreeze里面session是怎样实现的呢,

 1 protected function SetCurrentUser(IAuthenticatable $user)
 2     {
 3         $this->_cu = $user;
 4         Authenticator::SetCurrentUser($user,$this->GUID);
 5 
 6         // assign some global variables to the view
 7         $this->Assign("CURRENT_USER",$this->GetCurrentUser());
 8     }
 9 
10 public static function SetCurrentUser(IAuthenticatable $user, $guid = "CURRENT_USER")
11     {
12         self::UnsetAllSessionVars(); // this calls Init so we don't have to here
13         self::$user = $user;
14         $_SESSION[$guid] = serialize($user);//我们可以看出,在phreeze里面存储的session是元值序列化之后的字符串
15     }

我们得到序列化之后的值:controller.php里面的getCurrentUser,以及它里面调用的GetCurrentUser,我这里只有它调用的那个代码

 1 public static function GetCurrentUser($guid = "CURRENT_USER")
 2     {
 3         if (self::$user == null)
 4         {
 5             self::Init();
 6             
 7             if (isset($_SESSION[$guid]))
 8             {
 9                 self::$user = unserialize($_SESSION[$guid]);//翻序列化的值
10             }        
11         }
12         return self::$user;
13     }
14 
15     
在我们需要验证的时候,phreezeable.php里面有这个 
1
public function Validate() 2 { 3 // force re-validation 4 $this->ResetValidationErrors(); 5 6 $is_valid = (!$this->HasValidationErrors()); 7 8 // if validation fails, remove this object from the cache otherwise invalid values can 9 // hang around and cause troubles. 10 if (!$is_valid) 11 { 12 $this->_phreezer->DeleteCache(get_class($this), $this->GetPrimaryKeyValue()); 13 } 14 15 return $is_valid; 16 }

看两个文件的源码:requestUtil.php和VerySimpleStringUtil.php;

当我们需要为我们的页面进行分页的时候,Phreezer.php里面的Queery返回的DateSet对象,调用DateSet里面的方法GetDataPage(),源码自己看吧

actionRouter.php源代码自己看看,

未完待续。。。

原文地址:https://www.cnblogs.com/zhangjun516/p/2931877.html