php - Simple ORM Structure Codeigniter -
this code:
<?php class vortexorm { private static $orm = null; public function __get($name) { homecoming $this->$name; } public function __set($name, $value) { $this->$name = $value; } public static function getinstance() { if (vortexorm::$orm == null) vortexorm::$orm = new vortexorm(); homecoming 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>]"; homecoming $orm->$name; } }
to info use:
var_dump(vortexorm::get('admin_links')); var_dump(vortexorm::get('admin'));
to set info use:
vortexorm::set('admin_links',array(....));
however, next warnings:
a php error encountered severity: notice message: undefined property: vortexorm::$admin_links filename: vortex/vortexorm.php line number: 8 null php error encountered severity: notice message: undefined property: vortexorm::$admin filename: vortex/vortexorm.php line number: 8
why getting these warnings?
i want able access in codeigniter static function:
$this->vortexorm->admin_links = array(....);
ok, tested code:
<?php /* * alter template, take tools | templates * , open template in editor. */ class vortexorm { private static $orm = null; public function __get($name) { homecoming $this->$name; } public function __set($name, $value) { $this->$name = $value; } public static function getinstance() { if (vortexorm::$orm == null) vortexorm::$orm = new vortexorm(); homecoming 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>]"; homecoming $orm->$name; } } vortexorm::set('admin_links',"test"); var_dump(vortexorm::get('admin_links'));
it worked fine me. giving next output:
string(4) "test"
so, guess, might trying retrieve property before set? or please share more details. also, why trying create new orm, can use doctrine codeigniter easily?
php codeigniter properties undefined
No comments:
Post a Comment