2011-05-11 50 views
2

我有一個wordpress網站。我正在爲wordpress寫插件,我想在插件中使用codeigniter框架。我遇到了這個問題,因爲codeigniter引導文件「index.php」希望在全局範圍內運行,而不是在函數中運行。如何在wordpress插件中包含代碼點火器?

 
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 

下面的錯誤正在被拋出: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

我相信這是因爲笨期待其引導index.php文件在全球範圍運行。

任何想法?

+3

你想使用這個wordpress插件的codeigniter的哪些部分?這看起來過於複雜。 – Aren 2011-05-12 00:15:52

+0

我想在codeigniter中使用url功能,它將自動調用基於url的控制器/方法......並且這將包含在wordpress插件中。 – Abraham 2011-05-12 00:30:35

+4

我不知道,聽起來你正在試圖在我的一個方孔裏裝一個圓釘。 – Aren 2011-05-12 00:36:39

回答

1

這裏是你的選擇:

  1. 重寫URL(使用你的服務器),它具有一定的標識符被髮送到代碼點火器引導
  2. 重寫CI的路由鍋爐板開始調整到不被貫穿引導在全球範圍內
  3. 使用一個小的MVC插件在WordPress的,而不是CI

我將覆蓋第一個因爲我認爲它使m個如果你會頑固地堅持CI的話,這種感覺真的很重要。我將給你一些使用Apache作爲web服務器和mod_rewrite來實現這個概念的概念驗證碼。

基本上我們所能達到的就是你向我們展示的代碼,但是我們會讓apache爲我們做這件事,儘管它在全球範圍內引導,CI仍然可以運行。

你所要做的就是向wordpress .htaccess -file添加更多規則。就像這樣:

<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> 

我們www.example.com/CI/...所有請求將被傳遞到CI的引導了全球範圍。

+0

上面提到的mod-rewrite解決方案並不能解決問題。這不包括wordpress上下文中的codeigniter。做mod重寫解決方案就好像我沒有運行wordpress一樣。我正在尋找的解決方案是我可以在wordpress中,並使codeigniter成爲我的插件框架。 – Abraham 2011-05-19 07:44:31

+0

爲什麼你告訴我們代碼說你想要這個確切的東西呢?你需要更好地解釋。你想使用WordPress的主題引擎,然後在主題中運行插件功能?然後使用插件來生成插件功能的輸出? – rzetterberg 2011-05-19 14:03:46