Hi, I want to set up in settings table variables for pagination, admin_email and so on. This vars will be set up only once and I need them to call for different purposses.
for example.
....
.
$content = new Content();
$content->id = "$id";
$content->name = "$name";
..
$content->create();
//send email notification
$from = this var is under Settings class
$to = this var is under Settings class
$content->send_email($from, $to, $name);
Obviosly I cannot access them with Settings::$site_admin_email
and I dont want to access with instantiating Settings object with $set = new Settings();
and then getter from settings.
Because it will store only one row of information I guess there is simplier way to do this.
Why?
class Settings
{
static protected
$store = array();
static public function Get($key){
return self::$store[$key];
}
static public function Set($key, $value){
self::$store[$key] = $value;
}
static public function Has($key){
return array_key_exists(
$key,
self::$store
);
}
}
thanks for fast response Anthony,
I tried your class
<?php
class Settings{
public $site_name;
public $site_desc;
public $site_meta;
public $site_admin_email;
public $site_receive_email;
public $site_pagination_per_category;
static protected
$store = array();
static public function Get($key){
return self::$store[$key];
}
static public function Set($key, $value){
self::$store[$key] = $value;
}
static public function Has($key){
return array_key_exists(
$key,
self::$store
);
}
}
?>
and I got this error message
Fatal error: Access to undeclared static property: Settings::$site_admin_email
You need to ‘set’ the variables to be stored first. 
#somewhere at the start of your application
Settings::Set('admin.email.address', 'you@example.org');
Settings::Set('admin.email.subject', 'Website Notification');
Settings::Set('site.domain.name', 'example.org');
#anywhere else in your application, but within the same request
mail(
Settings::Get('admin.email.address'),
Settings::Get('admin.email.subject'),
sprintf(
'Hey, someone has just registered at %s!',
Settings::Get('site.domain.name')
)
);
#which, is the same as...
mail(
'you@example.org',
'Website Notification',
'Hey, someone has just registered at example.org!'
)