-1

我正在尝试推出自己的项目,但是遇到了一个错误,我发现这个错误有点古怪,而且我的 IDE 和 xDebug 并没有为像我这样的新手提供很多选择。

下面的代码有几个问题,但是使用未定义的常量包含 - 假设“包含”让我很烦,我不知道出了什么问题。

<?php

//Debug Error Reporting Configuration
error_reporting(E_ALL);


/*
    Do Not Change any of these items unless 
    you know what they do and you realy 
    have to change them
*/

//Global Function to return includes path
function includes($path, $location){
    return $_SERVER['DOCUMENT_ROOT']. "/" .$path. "/" .$location;
}

//Global Function to return single location path
function location($path){
    return $_SERVER['DOCUMENT_ROOT']. "/" .$path;
}

//Global Functions Include
require(includes(includes, 'functions.php'));

//Messaging Array
$messages=array();

//Database Configuration & Connection
$dbhost="localhost";
$dbuser="root";
$dbpass="SaltWater";
$dbname="platform";

connectToDB();

//Session Variable Registration
session_register("f_name");
session_register("user_id");
session_register("company_id");

//Smarty Template Engine Configuration
define('SMARTY_DIR',  includes(includes, smarty));
require(SMARTY_DIR . 'Smarty.class.php');

$smarty = new Smarty();
$smarty->setTemplateDir(location(templates));
$smarty->setCompileDir(location(cache));
$smarty->setCacheDir(location(cache));


function errorsys($type, $detail){

    $smarty->assign('type',$type);
    $smarty->assign('detail',$detail);
    $smarty->display('error.tpl');
}

?>

编辑:有没有一种我还没有发现的更简单的方法来做一个聪明的方法来做我的包含,而不需要通常在文件夹中向下钻取,以防它被部署到不同的服务器上?

4

2 回答 2

1
require(includes('includes', 'functions.php'));

您需要确保传递给包含函数的路径是字符串。如果没有引号,PHP 会认为您正在传递一个从未声明过的常量。该代码仍然可以工作,因为 PHP 会假定您的意思是一个字符串,但它会发出警告。

于 2013-02-01T09:21:20.800 回答
0

包含在某处定义为常量吗?也许你的意思是

require(includes(includes, 'functions.php'));  //if constant includes is defined

或者

require(includes($includes, 'functions.php'));  //if path is stored in $includes

或者你的意思是

require(includes('includes', 'functions.php')); //if path is 'includes/'
于 2013-02-01T09:19:23.307 回答