初学 Phreeze 4

本文深入解析了Phreeze框架中session的实现机制,包括序列化存储、验证及分页操作,详细解读了session存储过程及使用场景。

在项目中我们时常会用到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/archive/2013/02/25/2931877.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值