这是我的代码:
<?php
class VortexORM {
private static $orm = null;
public function __get($name) {
return $this->$name;
}
public function __set($name, $value) {
$this->$name = $value;
}
public static function getInstance() {
if (VortexORM::$orm == null)
VortexORM::$orm = new VortexORM();
return VortexORM::$orm;
}
public static function set($name, $value) {
$orm = VortexORM::getInstance();
//echo "Setting [ <b>{$name}</b> :: <i>{$value}</i>]";
$orm->$name = $value;
}
public static function get($name) {
$orm = VortexORM::getInstance();
// echo "Getting [ <b>{$name}</b> :: <i>{$orm->$name}</i>]";
return $orm->$name;
}
}要获取我使用的数据:
var_dump(VortexORM::get('admin_links'));
var_dump(VortexORM::get('admin'));要设置我使用的数据:
VortexORM::set('admin_links',array(....));但是,我得到以下警告:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: VortexORM::$admin_links
Filename: Vortex/VortexORM.php
Line Number: 8
NULL
A PHP Error was encountered
Severity: Notice
Message: Undefined property: VortexORM::$admin
Filename: Vortex/VortexORM.php
Line Number: 8为什么我会收到这些警告?
我希望能够在CodeIgniter中以静态函数的形式访问它:
$this->vortexorm->admin_links = array(....);发布于 2013-02-16 15:51:20
好的,我刚刚测试了这段代码:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class VortexORM {
private static $orm = null;
public function __get($name) {
return $this->$name;
}
public function __set($name, $value) {
$this->$name = $value;
}
public static function getInstance() {
if (VortexORM::$orm == null)
VortexORM::$orm = new VortexORM();
return VortexORM::$orm;
}
public static function set($name, $value) {
$orm = VortexORM::getInstance();
//echo "Setting [ <b>{$name}</b> :: <i>{$value}</i>]";
$orm->$name = $value;
}
public static function get($name) {
$orm = VortexORM::getInstance();
// echo "Getting [ <b>{$name}</b> :: <i>{$orm->$name}</i>]";
return $orm->$name;
}
}
VortexORM::set('admin_links',"test");
var_dump(VortexORM::get('admin_links'));它对我来说工作得很好。给出了以下输出:
string(4) "test" 所以,我猜,你可能只是试图在属性集之前检索它?或者请分享更多详细信息。另外,你为什么要尝试创建新的ORM,在那里我们可以很容易地使用use doctrine with codeigniter?
https://stackoverflow.com/questions/14904060
复制相似问题