php 如何在 codeigniter 中 require_once
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17977805/
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
how to require_once in codeigniter
提问by Ahmed-Anas
I am trying to extend a library in codeigniter. The only way to do so seems to include the original library using require_once
then load the extended library using $this->load->library()
我正在尝试在 codeigniter 中扩展一个库。这样做的唯一方法似乎是使用包含原始库require_once
然后使用加载扩展库$this->load->library()
right now I have tried
现在我已经尝试过
require_once('ion_auth.php');
require_once('home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
require_once('/home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
require_once('ion_auth.php');
require_once('home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
require_once('/home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
but unfortunately not luck..... I keep getting this error
但不幸的是不是运气..... 我不断收到这个错误
Message: require_once(...) [function.require-once]: failed to open stream: No such file or directory
Weird thing is though this works on my local xampp environment but not on the actual server.
奇怪的是,虽然这适用于我的本地 xampp 环境,但不适用于实际服务器。
回答by user20232359723568423357842364
Use CodeIgniter's built in constant, APPPATH
使用 CodeIgniter 的内置常量, APPPATH
require_once(APPPATH.'libraries/ion_auth.php');
require_once(APPPATH.'libraries/ion_auth.php');
回答by Jahmic
If the library is a codeigniter specific library, as sbaaaang points out, you should use:
如果库是特定于 codeigniter 的库,正如 sbaaaang 指出的那样,您应该使用:
$this->load->library('ion_auth');
However, if the library is just a generic PHP class or set of functions, the codeiginter loader may not recognize it. Then you will need to use either one of the generic loading operators (include, include_once, require, require_once), with the APPPATH constant, as also pointed out:
但是,如果库只是一个通用的 PHP 类或一组函数,则 codeiginter 加载器可能无法识别它。然后,您将需要使用通用加载运算符之一(包括、include_once、require、require_once),以及 APPPATH 常量,正如还指出的:
require_once(APPPATH.'libraries/ion_auth.php');
回答by Vahid Najafi
In a real server, you should use library's UPPERCASEname. like this:
在真实服务器中,您应该使用库的大写名称。像这样:
require_once(APPPATH.'libraries/Ion_auth.php');
回答by itsme
Do you know that Codeigniter has a loader class?
你知道 Codeigniter 有一个加载器类吗?
change this
改变这个
require_once('/home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
to
到
$this->load->library('ion_auth');
and be sure your libraries/ion_auth.php file it's a class named `class ion_auth{}`