【问题标题】:Accessing a Local Variable through Xajax and Classes in PHP通过 Xajax 和 PHP 中的类访问局部变量
【发布时间】:2011-03-03 17:39:22
【问题描述】:

我有一个班级

<?php
class cms{
    private $dataset;
    private $columns;
    private $configs;    

    public function __construct(){
        global $frw, $dbg;
        $this->configs =array();
    }

    public function __get($key){
        if(array_key_exists($key, $this->configs)==true){
            return $this->configs[$key];
        }else{
            throw new Exception('Unable to get value from configuration. '.$key);
        }
    }

    public function __set($key, $value){
        if(array_key_exists($key,$this->configs)){
            throw new Exception('Unable to set configuration. '.$key);
        }else{
            $this->configs[$key] = $value;
        }
    }

    public function exists($key){
        if(isset($this->configs[$key])){
            return true;
        }else{
            return false;
        }
    }


  public function load(){

  }

}
?>

$cms = 新 $cms;

我需要在页面上设置一个变量来实例化对象并且在每个页面中全局可用(在会话期间)。我不想要会话变量,也不想使用全局变量。有没有办法在页面之间传递 $dataset 并在 xajax 加载中调用 $cms->dataset。我一直在想我应该可以设置一个变量$dataset = $cms-&gt;__get('dataset');

【问题讨论】:

    标签: php xajax


    【解决方案1】:

    现在将$dataset 声明为公共private $dataset 在课堂外无法访问

    public $dataset;
    

    可在课堂外访问

    $cms->dataset
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多