在Wordpress中加载CodeIgniter实例 [英] Load CodeIgniter Instance in Wordpress

查看:74
本文介绍了在Wordpress中加载CodeIgniter实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Wordpress时遇到的问题是要将CodeIgniter功能合并到Wordpress主题文件中。例如,在我的许多CodeIgniter视图文件中都包含一个页眉和页脚。同样的页眉和页脚也需要包含在Wordpress主题中。

The problem I had with using Wordpress was wanting to incorporate CodeIgniter functionality into Wordpress theme files. For example, there are a header and footer that I include in many of my CodeIgniter view files. That same header and footer also needed to be included in the Wordpress theme.

这个想法是加载CI实例并在Wordpress上使用它。
任何帮助将不胜感激!

The idea is to load CI instance and use it on Wordpress. Any help would be appreciated!

我已经尝试过了。

I have tried this.

https:// github .com / falexandrou / Codeigniter-Wordpress-Integration

加载CI引导程序的文件路径已经正确。
结果为错误

The file path to load CI bootstrap is correct already. Its result was Error

Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php

网站步骤:

1.将其包含在顶部的以下模板文件中:

the sites step:
1. Include this in the following template files at the top:

 - 404.php - index.php- archive.php- archives.php
 - links.php -page.php - search.php - single.php */

 <?php
  $wp_ci['return'] = true;
 require('codeigniter.php');




  1. 沿着模板dir放置codeigniter文件

    应该加载CI实例,以便可以在Wordpress中使用。


    https://github.com/falexandrou/Codeigniter-Wordpress-Integration/blob/master/ci-wp-thedaylightstudio/codeigniter.php

  1. put codeigniter file along the template dir
    This is supposed to load CI instance so it can be used in Wordpress.
    https://github.com/falexandrou/Codeigniter-Wordpress-Integration/blob/master/ci-wp-thedaylightstudio/codeigniter.php

CI index.php

CI index.php

 <?php
 $wp_did_header = true;         
 require_once dirname( __FILE__ ) .'/blog/wp-blog-header.php';
 define('WP_USE_THEMES', true);
 require_once BASEPATH.'core/CodeIgniter.php';
 ?>

更新:

wp-blog- header

wp-blog-header

  if ( !isset($wp_did_header) ) {
$wp_did_header = true;
require_once( dirname(__FILE__) . '/wp-load.php' );
wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
 }

我在wordpress上成功加载了codeigniter视图,但是
都是我的ci_site_url函数返回 website.com/blog/application
时应为 website.com/application
我将此代码放在WP主题之一 index.php

I successfully load the codeigniter view on wordpress but all my ci_site_url function returns website.com/blog/application when it should be website.com/application I put this code on one of WP theme index.php

  define('STDIN', TRUE);
  $_SERVER['argv'] = array();
  ob_start();
  require('../index.php');
  $GLOBALS['wp_ci_output'] = ob_get_contents();
  ob_end_clean();
  $GLOBALS['CI'] = get_instance();
  require_once(APPPATH.'helpers/wordpress_helper.php');

代码参考:

http://thedaylightstudio.com/blog/2010/06/16/codeigniter-和wordpress集成

wordpress-helper.php

wordpress-helper.php

/**
* Print codeigniter view file in wordpress content
*
* @access   public
* @param    string view file name
* @param    array array of variables to be rendered
* @param    boolean true to return, false to return
* @return   mixed
*/

function wp_ci_load_view($view, $vars = array(), $return = FALSE){
 extract($vars);
  $file = APPPATH.'/views/'.$view.'.php';
  $contents = file_get_contents($file);
  //echo $contents;
  $CI =& get_instance();
  $check_funcs = array('ci_site_url(', '$this->');

  $replace_funcs = array('site_url_wp_safe(', '$CI->');
  $contents = str_replace($check_funcs, $replace_funcs, $contents);
  $contents = eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", 
  str_replace('<?=', '<?php echo ', $contents)).'<?php ');

   if ($return === TRUE){
   return $contents;
   }
 }

https ://github.com/falexandrou/Codeigniter-Wordpress-Integration/blob/master/ci-wp-thedaylightstudio/wordpress_helper.php

作者做了说一个问题:
此版本的唯一问题是,它总是呈现相同的CI页面以获取CI对象,并且您无法操纵它呈现的页面。谢谢。

The writer did say an issue: The only issue with this version is that it always renders the same CI page to get the CI object and you can’t manipulate which page it renders. Thanks.

MY_url_helper

MY_url_helper

功能ci_site_url :区分CI site_url和WP网站url功能

function ci_site_url: to differ CI site_url and WP site url function

 if ( ! function_exists('ci_site_url')){
   function ci_site_url($uri = '')
   {
    $CI =& get_instance();
    return $CI->config->site_url($uri);
    }
  }


推荐答案

外观我已经在我的 helper文件的codeigniter中添加了以下代码,并在config / autoload.php文件中添加了该帮助程序以自动将其自动加载。

look I have added below code in my helper file of codeigniter and add this helper in config/autoload.php file to autoload it automatically.

/**
 * return CI header to home page cms for 
 */
if (!function_exists('ci_header')) {

    function ci_header() {
        $CI = & get_instance();
        $header = $CI->load->view('includes/header.php', '', true);

        return $header;
    }

}

/**
 * return CI footer to home page cms for 
 */
if (!function_exists('ci_footer')) {

    function ci_footer() {
        $CI = & get_instance();
        $footer = $CI->load->view('includes/footer_homepage.php', '', true);

        return $footer;
    }

}

并在wordpress中放置以下代码 wp-content / themes / my_theme / header.php

and put below code in wordpress wp-content/themes/my_theme/header.php

<?php
    echo ci_header();
?>

并在wordpress wp-content / themes / my_theme / footer.php

and put below code in wordpress wp-content/themes/my_theme/footer.php

<?php
echo ci_footer();
?>

您可以在wordpress主题模板中直接使用任何帮助功能,因为我正在呼叫 ci_header() ci_footer();

you can use any helper function in wordpress theme templete directly as i am calling ci_header() and ci_footer();

继续...,总结一下我还需要为项目做些什么...

Go ahead... and summarize me what else you need to do for your project...

这篇关于在Wordpress中加载CodeIgniter实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆