这是我的代码:
<?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(....);
好的,我刚刚测试了这个代码:
<?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,在那里我们可以很容易地将条令与代码点火器一起使用?