我是Phalcon PHP框架的新手,目前我正在尝试使用Controller中的持久存储(通过$this->persistent
访问)。我知道持久存储使用Session \ Bag,根据the API我可以通过remove()
或__unset
魔术方法移除属性。
所以,我创建了这个小控制器来测试持久存储:
<?php
class Control1Controller extends Phalcon\Mvc\Controller
{
public function cobaAction()
{
echo '<pre>';
$this->persistent->destroy();
$this->dump('anu');
echo "Set\n";
$this->persistent->anu = 'Aloha';
$this->dump('anu');
echo "Remove\n";
$this->persistent->remove('anu');
$this->dump('anu');
echo "set\n";
$this->persistent->anu = 'Aloha';
$this->dump('anu');
echo "assign null\n";
$this->persistent->anu = null;
$this->dump('anu');
echo "set\n";
$this->persistent->anu = 'Aloha';
$this->dump('anu');
echo "destroy\n";
$this->persistent->destroy();
$this->dump('anu');
}
private function dump($anu)
{
echo $anu.'='.var_export($this->persistent->$anu, true)."\n";
echo 'has('.$anu.')='.var_export($this->persistent->has($anu), true)."\n";
echo 'isset('.$anu.')='.var_export(isset($this->persistent->$anu), true)."\n";
echo "\n";
}
}
当我访问该操作时,这是我得到的结果:
anu=NULL
has(anu)=false
isset(anu)=false
Set
anu='Aloha'
has(anu)=true
isset(anu)=true
Remove
anu='Aloha'
has(anu)=true
isset(anu)=true
set
anu='Aloha'
has(anu)=true
isset(anu)=true
assign null
anu=NULL
has(anu)=true
isset(anu)=true
set
anu='Aloha'
has(anu)=true
isset(anu)=true
destroy
anu=NULL
has(anu)=false
isset(anu)=false
现在这很奇怪,我希望在致电->remove('anu')
并设置anu = null
后,has()
和isset()
会返回false
,但事实并非如此。那是为什么?
答案 0 :(得分:1)
这已在1.2.5和1.3.0分支中修复,请参阅https://github.com/phalcon/cphalcon/pull/1639和https://github.com/phalcon/cphalcon/pull/1640