php 在 Codeigniter 中使用 require_once

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6734976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:07:10  来源:igfitidea点击:

Using require_once in Codeigniter

phpcodeigniter

提问by Nyxynyxx

How do I use the require_oncephp function in Codeigniter on a normal PHP file? I', currently getting an error.

如何require_once在普通 PHP 文件上使用Codeigniter 中的php 函数?我',目前出现错误。

Code:

代码:

require_once($_SERVER['DOCUMENT_ROOT'].'/php/jformer.php');

require_once($_SERVER['DOCUMENT_ROOT'].'/php/jformer.php');

Error:

错误:

Message: require_once() [function.require-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0

Message: require_once() [function.require-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0

Message: require_once(http://localhost/site/php/jformer.php) [function.require-once]: failed to open stream: no suitable wrapper could be found

Message: require_once(http://localhost/site/php/jformer.php) [function.require-once]: failed to open stream: no suitable wrapper could be found

回答by Rocket Hazmat

You don't use $_SERVER['DOCUMENT_ROOT']for this, you want to use APPPATHor BASEPATHinstead, or just type the full path to the file. require_onceshould be passed a local file, not a URL.

你不使用$_SERVER['DOCUMENT_ROOT']这个,你想使用APPPATHorBASEPATH代替,或者只是输入文件的完整路径。 require_once应该传递一个本地文件,而不是一个 URL。

回答by Anshuman

You should be using the path to the file and not the URL. Best (and certainly CI friendly) way would be to use BASEPATHor APPPATHconstants.

您应该使用文件的路径而不是 URL。最好的(当然也是 CI 友好的)方法是使用BASEPATHAPPPATH常量。