我想在我的机器和服务器上进行开发时设置特定的自定义常量,所以我在constants.php文件中编写了类似的内容:
if ( ! function_exists('is_dev_environment')){
function is_dev_environment()
{
//the magic
}
{
if (is_dev_environment()){
defined('REPORTS_DIR') OR define('REPORTS_DIR', 'downloads/reports');
}else{
defined('REPORTS_DIR') OR define('REPORTS_DIR', 'other_dir');
}
工作正常,但当然我也不想在database.php中编写代码。所以我试着把代码放在config文件夹中的另一个文件other.php中,只是:
include "other.php";
并调用is_dev_environment()函数,但是我遇到以下错误:
Warning: include(environment_helper): failed to open stream: No such file or directory in C:\xampp\htdocs\Teilestammblatt\application\config\constants.php on line 4
Warning: include(): Failed opening 'environment_helper' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Teilestammblatt\application\config\constants.php on line 4
Fatal error: Uncaught Error: Call to undefined function is_dev_environment() in C:\xampp\htdocs\Teilestammblatt\application\config\constants.php:103 Stack trace: #0 C:\xampp\htdocs\Teilestammblatt\system\core\CodeIgniter.php(70): require_once() #1 C:\xampp\htdocs\Teilestammblatt\index.php(315): require_once('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Teilestammblatt\application\config\constants.php on line 103
我已经尝试将other.php文件放在helper文件夹中,将其重命名为other_helper.php并自动加载它,但这也不起作用,如
$this->load->helper("other");
我是codeignator和php的新手,我无法在stackoverflow上找到解决问题的问题。我错过了什么?
编辑:
include APPPATH.'config'.'\\yourfile.php';
做了这个伎俩,因为我希望能够在不同的环境中完成它而不使用绝对路径。这包括在definend APPPATH之后的index.php文件和index.php文件顶部的$ application_folder中的工作:
$application_folder = 'application';
define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
include APPPATH.'config'.'\\yourfile.php';
请注意
define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
应仅在此文件中定义一次,否则php将显示“通知”警告。