dousuie2222 2009-11-30 22:41
浏览 33

Php抽象类站点配置

i have a config class which is an abstract class. I would like to set it up so it automatically detects which server the site is on and then assigns appropriate constants. I get an error on line ten $this->hostName = $_SERVER['SERVER_NAME']; expecting `T_FUNCTION. What is the correct way to do this and is there a better way to do this? Here is the first part of my class

abstract class config{

 public $hostName;
 public $hostSlices;
 public $domain;
echo $_SERVER['SERVER_NAME'];
//strips out the "www" from the server name but only if it has the name on it . 
$this->hostName = $_SERVER['SERVER_NAME'];
$this->hostSlices = explode(".",$this->hostName);
if($this->hostSlices[0]=="www"){array_shift($this->hostSlices);}
$this->domain = join(".",$this->hostSlices);

//depending on which domain is used, different config setup is used. 
switch ($this->domain){
    case "localhost":*/

  const HOST = "localhost";//would http://localhost/ work as well. In that case, then this and the SITE_ROOT  could be the same variable and i would preferentially set them depending on the host that the site is on.
  const USER = "root";
  const PWD = "xxxxxxx";
  const NAME = "hurunuitconz";//database name

  //public $name = "hello from the config class";//you cannot access variables from an abstract class  you should define constants and then the can be used anywhere

 ###########Location of 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";//would http://localhost/ work as well. In that case, then this and the SITE_ROOT  could be the same variable and i would preferentially set them depending on the host that the site is on.
  const USER = "charles_andrew";
  const PWD = "xxxxxxx";
  const NAME = "charles_hurunuitconz";//database name
 ###########Location of file groups########
  const SITE_ROOT = "http://charles.hughs.natcoll.net.nz/_Assignments/Industry/www";//this is just confusing the way natcoll makes us do this. 
  const ADMIN_IMAGES = 'http://charles.hughs.natcoll.net.nz/_Assignments/Industry/www/images/user_images/admin_images';

        break;
    }
  • 写回答

4条回答 默认 最新

  • dsfgdsjfd78773 2009-11-30 22:45
    关注

    You have to wrap all that code in a constructor or better yet a function called init() or somthing. Then when you override init in the child classes you would call parent::init(). Did you mean to make this class static, not abstract?

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起