【问题标题】:Cannot Remove A Property From Phalcon Persistent Storage (Session Bag)无法从 Phalcon 持久存储(会话包)中删除属性
【发布时间】:2013-11-21 03:27:38
【问题描述】:

我是 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

现在这很奇怪,我希望在调用 -&gt;remove('anu') 并设置 anu = null 之后,has()isset() 会返回 false,但事实并非如此。这是为什么呢?

【问题讨论】:

标签: php session phalcon


【解决方案1】:

这已在 1.2.5 和 1.3.0 分支中修复,请参阅 https://github.com/phalcon/cphalcon/pull/1639https://github.com/phalcon/cphalcon/pull/1640

【讨论】:

    猜你喜欢
    • 2019-03-16
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    • 2013-04-07
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多