通过 Xajax 和 PHP 中的类访问局部变量
我有一个类
<?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 = new $cms;
我需要在页面上设置一个变量来实例化该对象,并且在每个页面中全局可用(在会话期间)。我不需要会话变量,也不想使用全局变量。有没有办法在页面之间传递 $dataset 并在 xajax 加载中调用 $cms->dataset 。我一直认为我应该能够设置一个变量 $dataset = $cms->__get('dataset');
I have a Class
<?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 = new $cms;
I need to have a variable set on the page that instatiates the object and is available globally throughout each page (for duration of session). I do not want a session variable and I'd like not to use a global. Is there a way of passing the $dataset between pages and calling $cms->dataset in an xajax load. I keep thinking that I should be able to set a variable $dataset = $cms->__get('dataset');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在将
$dataset
声明为 publicprivate $dataset
无法在类外部访问,但可以在类外部访问
Declare
$dataset
as public right nowprivate $dataset
is not accessible out side the classwill be accessible outside the class