Tuesday 15 March 2011

oop - Php abstract class site configuration -


I have a config class which is an abstract class. I want to set it so it automatically detects it That's what the server on the site and then assigns the appropriate constant. Let me line ten $ this-> hostName = $ _SERVER ['SERVER_NAME']; What is the correct way to do this rather than 'T_FUNCTION' and what is the better way to do it? Here is the first part of my class

  Abstract class config {public $ hostName; Public $ hostSlices; Public $ domain; Copy $ _SERVER ['SERVER_NAME']; // Exits "www" by the server name, but only then does it have the name $ -This-> Hostname = $ _SERVER ['SERVER_NAME']; $ This- & gt; Hostslites = Explosions (".", $ This-> Hostname); If ($ the-> hostSlices [0] == "www") {array_shift ($ this-> hostSlices);} $ this- & gt; Domain = join (".", $ This-> Hostslips); // Depending on the usage of this domain, different configuration setup is used. Switch ($ this- & gt; domain) {case "localhost": * / const HOST = "localhost"; // will http: // localhost / work also In that case, then this and SITE_ROOT can be the same variable and I can set them primarily on the basis of the host that the site is running Const. USER = "root"; Const. PWD = "xxxxxxx"; Const NAME = "hurunuitconz"; // database name // public $ name = "hello from config class"; // You can not access the variable from an abstract class, which you should define constants and then can be used anywhere #### ####### The location of the file groups ###### ## const SITE_ROOT = "http: // localhost"; Const ADMIN_IMAGES = 'http: // localhost / images / user_images / admin_images'; break; Case "charles.hughs.natcoll.net.nz": const HOST = "charles.hughs.natcoll.net.nz"; // will also be http: // localhost / work as well. In that case, then this and SITE_ROOT can be the same variable and I can set them primarily on the basis of that location on the site that the site is current Const USER = "Charles_Andrew"; Const. PWD = "xxxxxxx"; Const NAME = "charles_hurunuitconz"; // Database Name ########### Status of File Groups ######## const SITE_ROOT = "http://charles.hughs.natcoll.net.nz/ _Assignments/Indo/World "; // It is just the way natcoll confuses us in doing this. Const ADMIN_IMAGES = 'http://charles.hughs.natcoll.net.nz/_Assignments/Industry/www/images/user_images/admin_images'; break; }  

An abstract class should not allow you to set personal data (only one Heritage concrete square).

Also, take a look at the stack overflow for an interesting discussion on SERVER_NAME vs. HTTP_HOST

.

No comments:

Post a Comment