Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Wordpress中加载CodeIgniter实例_Php_Wordpress_Codeigniter - Fatal编程技术网

Php 在Wordpress中加载CodeIgniter实例

Php 在Wordpress中加载CodeIgniter实例,php,wordpress,codeigniter,Php,Wordpress,Codeigniter,我在使用Wordpress时遇到的问题是希望将CodeIgniter功能合并到Wordpress主题文件中。例如,我的许多CodeIgniter视图文件中都包含了页眉和页脚。同样的页眉和页脚也需要包含在Wordpress主题中 想法是加载CI实例并在Wordpress上使用它。 任何帮助都将不胜感激 我试过这个 加载CI引导的文件路径已经正确。 其结果是错误的 Your system folder path does not appear to be set correctly. Please

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

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

我试过这个

加载CI引导的文件路径已经正确。 其结果是错误的

Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php
站点步骤:
1.将其包含在顶部的以下模板文件中:

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

 <?php
  $wp_ci['return'] = true;
 require('codeigniter.php');
我成功地在wordpress上加载了codeigniter视图,但是 所有my ci_site_url函数返回
website.com/blog/application
应该是
website.com/application
我把这段代码放在WP主题
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');
代码参考:

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

看,我在codeigniter的助手文件中添加了以下代码,并在config/autoload.php文件中添加此助手以自动加载它

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

<?php
    echo ci_header();
?>
<?php
echo ci_footer();
?>
当我调用
ci_header()
ci_footer()时,您可以直接使用wordpress主题模板中的任何帮助函数

<?php
    echo ci_header();
?>
<?php
echo ci_footer();
?>

继续。。。并总结一下你还需要为你的项目做些什么

您正在使用什么版本的WP?@M.Doye Hi。我正在使用WP 4.1.1,您可能需要交换
require_once dirname(u_文件_uu)。'/blog/WP blog header.php'require_once('path/to/wp load.php')的code>
换句话说,使用
wp load.php
而不是
wp blog header.php
@M.Doye我已经更改了它,但没有更改。我想我用哪一个无关紧要
wp blog header.php
也调用
wp load.php
文件。我已经更新了问题中的内容,我得到了“调用未定义函数”。我把wordpress安装在codeigniter的“应用程序”外的“博客”文件夹中。我还能做什么?我也有同样的问题。你是如何解决你的问题的?运气好吗?你在codeigniter中制作了一个助手吗?你在config/autoload.php中自动加载了这个助手吗?有人找到了解决方案吗@MIIB??
<?php
echo ci_footer();
?>