如何更正 codeIgniter 插件的 PHP 路径?

发布于 2024-09-01 23:23:39 字数 640 浏览 3 评论 0原文

我尝试自己将 Rediska(Redis PHP 客户端)安装到我的 codeigniter 应用程序中,但没有成功。当我尝试将其放入 Codeigniter 的插件文件夹时,我会收到大量“没有这样的文件或目录”错误:

严重性:警告

消息: require_once(Rediska/Connection/Exception.php) [function.require-once]:未能 打开流:没有这样的文件或目录

文件名:Rediska/Connection.php

行号:6

有人在我之前成功将 Rediska 安装到 Codeigniter 中吗?

从Rediska安装手册来看,它似乎是一个简单易用的直接安装: http://rediska.geometria-lab.ru/documentation/get-started/

由于现在仅涉及基于路径的错误,我假设应该有一些方便的 PHP 设置,我可以改变以使其一切正常?

谢谢!

I have tried by myself to install Rediska (Redis PHP client) into my codeigniter application, but without any success. I'll get insane amounts of "No such file or directory"-errors when trying to put it into the plugins folder of Codeigniter:

Severity: Warning

Message:
require_once(Rediska/Connection/Exception.php)
[function.require-once]: failed to
open stream: No such file or directory

Filename: Rediska/Connection.php

Line Number: 6

Have anyone succeeded to install Rediska into Codeigniter before me?

From looking at the Rediska install manual, It appears to be a simple and easy drop-in installation: http://rediska.geometria-lab.ru/documentation/get-started/

Since it's only about path-based errors right now, I'll assume that there's should be some handy PHP setting that I can change to make it all work?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

提笔落墨 2024-09-08 23:23:39

这是一个简单的 include_path 相关问题。换句话说,PHP 无法自动加载您尝试使用的库(在您的情况下为 Rediska)尝试加载的文件。

我假设您已将 Rediska 库目录的内容提取到 Code Igniter 的 system/application/libraries 目录中(以便在库目录中您有 Rediska.php 和 Rediska 目录)。您必须插入以下代码:

ini_set('include_path', ini_get('include_path').';'.APPPATH.'libraries/');

...到以下位置之一(由您选择哪一个):

  1. 修改主 index.php 文件,然后调用文件最底部的 require_once 函数
    • 进入您想要使用 Rediska 的(每个)控制器
    • 修改Rediska.php文件,并将此行添加到文件的最顶部(之后的第一行

然后,您应该能够使用以下几行(从您的控制器,甚至其他库)加载 rediska:

$this->load->library('rediska');
$rediska = new Rediska();

或者,您可能希望自动加载 Rediska 库,而不是手动加载库。有关更多信息,请参阅 http://codeigniter.com/user_guide/general/autoloader.html信息。

希望有帮助。

It's a simple include_path-related problem. In other words, PHP is unable to automatically load files that library you are trying to use (in your case Rediska) is trying to load.

I have assumed that you have extracted contents of Rediska library directory into system/application/libraries directory of Code Igniter (so that in libraries dir you have Rediska.php and Rediska directory). You will have to insert following code:

ini_set('include_path', ini_get('include_path').';'.APPPATH.'libraries/');

...into ONE of following places (it's up to you to choose which one):

  1. modify main index.php file, before call to require_once function at the very bottom of file
    • into (every) controller where you want to use Rediska
    • modify Rediska.php file, and add this line to the very top of file (first line after

Then, you should be able to load rediska using following lines (from your controller, or even some other library):

$this->load->library('rediska');
$rediska = new Rediska();

Alternatively, instead of manually loading library, you might want to auto-load Rediska library. See http://codeigniter.com/user_guide/general/autoloader.html for more info.

Hope it helps.

坚持沉默 2024-09-08 23:23:39

我没有让 ini_set 解决方案起作用,但是该行的一个变体效果很好:
set_include_path(get_include_path() . PATH_SEPARATOR . APPPATH.'libraries/');

I didn't get the ini_set solution to work, but a variant of that line works great:
set_include_path(get_include_path() . PATH_SEPARATOR . APPPATH.'libraries/');

堇色安年 2024-09-08 23:23:39

刚刚注意到 phil Sturgeon 关于插件变得多余的说明......

我目前正在将 Rediska 滚动到 CI 库中,但对于一般用途,您可以使用以下内容包含基于 CI 应用程序路径的文件

include(APPPATH.'libraries/rediska/Exception.php');

将在 system/applications/libraries/rediska/ 中包含 Exception.php

Just noticed the note from phil Sturgeon about plugins being made redundant.....

I'm working on rolling Rediska into a CI library at the moment, but for general use you can using the following to include files based on the CI application path

include(APPPATH.'libraries/rediska/Exception.php');

Would include the Exception.php in system/applications/libraries/rediska/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文