如何在 WordPress 插件中包含 CodeIgniter?
我有一个 WordPress 网站。我正在为 WordPress 编写一个插件,我想在插件中使用 CodeIgniter 框架。我遇到了这个问题,因为 CodeIgniter 引导文件“index.php”期望在全局范围内运行,而不是在函数内运行。
Right now, within my plugin, I do the following: // BEGIN: plugin code function classifieds_template_redirect() { global $wp; $plugin_path = plugin_dir_path(__FILE__); if (preg_match('/^CI/', $wp->request)) // Use CodeIgniter to handle the request { include($plugin_path."/index.php"; // Include the CodeIgniter bootstrap file die(); } } add_action( 'template_redirect', 'classifieds_template_redirect' ); // END: plugin code
抛出以下错误:
致命错误:在第 47 行 /usr/local/apache/htdocs/site.utils/htdocs/CodeIgniter/system/core/Utf8.php 中的非对象上调用成员函数 item()
我相信这是由于CodeIgniter 期望其引导程序 index.php 文件在全局范围内运行。
有什么想法吗?
I have a WordPress website. I am writing a plugin for WordPress where I want to use the CodeIgniter framework within the plugin. I am having trouble with this because the CodeIgniter bootstrap file "index.php" expects to be run in the global scope, not within a function.
Right now, within my plugin, I do the following: // BEGIN: plugin code function classifieds_template_redirect() { global $wp; $plugin_path = plugin_dir_path(__FILE__); if (preg_match('/^CI/', $wp->request)) // Use CodeIgniter to handle the request { include($plugin_path."/index.php"; // Include the CodeIgniter bootstrap file die(); } } add_action( 'template_redirect', 'classifieds_template_redirect' ); // END: plugin code
The following error is being throw:
Fatal error: Call to a member function item() on a non-object in /usr/local/apache/htdocs/site.utils/htdocs/CodeIgniter/system/core/Utf8.php on line 47
I believe this is due to CodeIgniter expecting its bootstrap index.php file to be run in global scope.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是您的选择:
我将介绍第一个,因为我认为如果您顽固地坚持使用 CodeIgniter,那么这是最有意义的。我将向您提供一些概念验证代码,使用 Apache 作为网络服务器和 mod_rewrite 来完成此任务。
基本上,我们将实现的只是您向我们展示的代码,但我们将让 Apache 为我们做这件事,使 CodeIgniter 通过其引导程序在全局范围内运行。
您所要做的就是向 WordPress
.htaccess
文件添加更多规则。像这样:现在所有对
www.example.com/CI/...
的请求都将在全局范围内传递到 CodeIgniter 的引导程序。Here are your options:
I am going to cover the first one, because I think that it makes the most sense if you are going to be stubborn about sticking with CodeIgniter. And I am going to give you some proof of concept code using Apache as the webserver and mod_rewrite to accomplish this.
Basically all we will achieve is your code you have shown us, but instead we will make Apache do it for us, making CodeIgniter being run though its bootstrap over global scope.
All you do is to add more rules to the WordPress
.htaccess
-file. Like this:Now all request to
www.example.com/CI/...
will be passed to CodeIgniter's bootstrap over global scope.