-2

当我将代码切换到另一个系统时,我收到错误(下面提到的代码),

配置:

操作系统:Windows 7 php 服务器:Xampp

请帮我解决这个问题。提前致谢。

代码:

<?php
class settings{
    public $theme;
    public $db_pf;

    function __construct(){
        $this->theme="default";
        $this->db_pf="task_";
        $this->paths();
        $this->abbr();
        $this->errors();

        $this->enable_db_config();
    }
    function paths(){
        define(ROOT,$_SERVER['DOCUMENT_ROOT']);
        define(BP,"/task/");
        define(ABSPATH,"/task/ta-admin/");
        define(ADMPATH,"/task/administrator/");
        define(INCLUDE_PATH,ABSPATH."includes/");
        define(MODULE_PATH,ABSPATH."modules/");
        define(CONTENT_PATH,ABSPATH."contents/");
        define(THEME_PATH,ABSPATH."templates/".$this->theme."/");
        define(STYLE_PATH,THEME_PATH."styles/");
        define(IMAGE_PATH,THEME_PATH."images/");
        define(JS_PATH,BP."assets/js/");
        define(JQ_PATH,BP."assets/jq/");
    }
    function enable_db_config(){
        include(ROOT.BP."ta-includes/class-db-config.php");
    }
    function abbr(){
        define(task_title,"Admin-Quit Tasker-");
        define(LOGIN_TITLE," Administrator Login...");
        define(SLOGAN,"Enabling Solutions to your Tasks...");
    }
    function errors(){
        define(NOTFOUND,"Page not found");
        define(GOBACK," please press ok to go back...");    
    }
}
$obj_settings=new settings();
?>

错误:

Notice: Use of undefined constant ROOT - assumed 'ROOT' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 14

Notice: Use of undefined constant BP - assumed 'BP' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 15

Notice: Use of undefined constant ABSPATH - assumed 'ABSPATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 16

Notice: Use of undefined constant INCLUDE_PATH - assumed 'INCLUDE_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 17

Notice: Use of undefined constant CONTENT_PATH - assumed 'CONTENT_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 18

Notice: Use of undefined constant THEME_PATH - assumed 'THEME_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 19

Notice: Use of undefined constant STYLE_PATH - assumed 'STYLE_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 20

Notice: Use of undefined constant JS_PATH - assumed 'JS_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 21

Notice: Use of undefined constant JQ_PATH - assumed 'JQ_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 22
4

2 回答 2

7

您的常量需要是字符串。因此,您必须将它们“包装”在这样的引号中:

define('ROOT',$_SERVER['DOCUMENT_ROOT']);
       ^    ^

如有疑问,请始终检查Manual,在这种情况下为 define()

补充:
在函数中定义常量也是,我发现,有点“狡猾”。如果您坚持不将它们移动到一config开始就加载的另一个(例如)文件,那么至少将它们从类结构中取出。

于 2012-06-28T11:22:17.753 回答
0

我认为您误解了定义和常量是什么/从对象中以这种方式定义常量并没有真正意义。

也许这是您正在做的更好的方法:

http://php.net/manual/en/language.oop5.constants.php

或者,使用定义设置项目的最常见用法是使用 si9mple 设置或配置文件...

于 2012-06-28T11:22:48.417 回答