Code: Select all
if ($audio == "1") {}Moderator: General Moderators
Code: Select all
if ($audio == "1") {}http://www.patternsforphp.com/wiki/Singleton wrote: Singletons as we have seen are a useful Design Pattern when used with care. They allow a single instance of any object to be globally available within an application.
You're thinking in terms of a sort of config.php file that defines settings and is included in every file. There's nothing wrong with that approach, and it's one of the great features of PHP.JAB Creations wrote:Am I considering a good approach or is there a better way?
Code: Select all
class css3 (
private $css3 = $css3;
if ($_SERVER['REQUEST_METHOD'] == "POST" && $_POST['formis'] == "siteoptions")
{
if (isset($_POST['css3']) && $_POST['css3']=='1') {setcookie('css3','1',time()+2592000,'/'); $css3 = "1"}
else if (!isset($_POST['css3'])) {setcookie('css3','0',time()+2592000,'/'); $css3 = "0"}
}
else if ($_SERVER['REQUEST_METHOD'] == "GET" && isset($_GET['css3']))
{
if ($_GET['css3'] == "0") {setcookie('css3','0',time()+2592000,'/'); $css3 = "0"}
else if ($_GET['css3'] == "1") {setcookie('css3','1',time()+2592000,'/'); $css3 = "1"}
}
else
{
if ($_COOKIE['css3'] == "0") {$css3 = "0"}
else if ($_COOKIE['css3'] == "1") {$css3 = "1"}
}Code: Select all
class setting {
function bark() {
print "Grrrrrrr...Woof...Woof!\n<br>";
}
}
class poodle extends setting {
function bark() {
print "Yip...Yeep...Yeeeeeeeeeeeeep!\n<br>";
}
}
$audio = new setting;
$audio->substringaudio = "audio";
print $audio->substringaudio . ' hello 123';
echo "\n<br>";
$audio->bark(); // function call bark() with class as setting
$connection = new poodle;
$connection->substringaudio = "connection";
print $connection->substringaudio;
echo "\n<br>";
$connection->bark(); // function call bark() with extended class as poodleCode: Select all
class setting {
//private $audio = 0;
function foo()
{
if ($_GET['audio'] == "0") {$thisaudio = 0; setcookie('audio','0',time()+2592000,'/');}
else if ($_GET['audio'] == "1") {$thisaudio = 1; setcookie('audio','1',time()+2592000,'/');}
else if ($_GET['audio'] == "2") {$thisaudio = 2; setcookie('audio','2',time()+2592000,'/');}
else if ($_COOKIE['audio'] == "0") {$thisaudio = 0; setcookie('audio','1',time()+2592000,'/');}
else if ($_COOKIE['audio'] == "1") {$thisaudio = 1; setcookie('audio','1',time()+2592000,'/');}
else if ($_COOKIE['audio'] == "2") {$thisaudio = 2; setcookie('audio','2',time()+2592000,'/');}
private $audio = $thisaudio;
} //foo()
private $ajax = true;
public function get($item){
return $this->$item;
}
}
//then call it like this
$setting = new setting();
$setting->get('audio');