duanba3707 2011-05-11 23:52
浏览 52

如何在wordpress插件中包含代码点火器?

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?

  • 写回答

1条回答 默认 最新

  • dongti7838 2011-05-18 21:14
    关注

    Here are your options:

    1. Rewrite urls (using your webserver) which starts with a certain identifier to get sent to Code igniters bootstrap
    2. Rewrite CI's routing boiler plate to adjust to not being run through bootstrap over global scope
    3. Use a small mvc plugin in Wordpress instead of CI

    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 CI. And I am going to give you some proof of concept code using Apache as 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 CI being run though it's bootstrap over global scope.

    All you do is to add more rules to the wordpress .htaccess-file. Like this:

    <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
    
            #Here's the code which rewrites the url to your CI plugin. 
            RewriteRule ^CI/(?.*)$ wp-content/plugins/ci-plugin/index.php/$1 [QSA,L]
    
            RewriteRule ^index\.php$ - [L]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . /index.php [L]
    
    </IfModule>
    

    Now all request to www.example.com/CI/... will be passed to CI's bootstrap over global scope.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100