Wordpress Codeigniter集成:如何替换CI上的site_url? [英] Wordpress Codeigniter Integration: How to replace site_url on CI?

查看:286
本文介绍了Wordpress Codeigniter集成:如何替换CI上的site_url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Wordpress和Codeigniter集成的URL有一些问题,因为我想避免WP和CI site_url之间的数据冲突。

I have some problem with URL of Wordpress and Codeigniter integration, because I want to avoid data collisions between WP and CI site_url.

这是我的代码在CI:

config.php

Here is my code on CI :
config.php

$config['base_url'] = 'http://www.mydomain.com';

my_helper.php

my_helper.php

add_filter('site_url', 'ci_site_url', 1);
function ci_site_url()
{
    include(APPPATH.'/config/config.php');
    return $config['base_url'];
}

它工作正常,并显示 http://www.domain.com

<?php
echo site_url();
?>

我想要 http://www.domain.com/index.php/admin/xxx 当我使用site_url('admin / xxx');

I want http://www.domain.com/index.php/admin/xxx when I use site_url('admin/xxx');

我一直在寻找答案,但我找不到,所以我要感谢任何帮助: - )

I have been looking for an answer here but I can't find it, so I would thank any help on this :-)

推荐答案

安装wordpress和codeigniter只是一块蛋糕。您需要执行以下操作。

我假设您需要在Codeigniter内部使用wordpress,所以这里是如何做到的。

Installing wordpress and codeigniter is just a piece of cake. you need to do the following.
I assume you need wordpress inside Codeigniter so here is how you can do it.

在wordpress目录中创建一个名为myci的文件夹

in wordpress directory create a folder called myci

wordpress/
         /myci

现在把codeigniter包放在myci中。接下来,您需要将此状态添加到 index.php

Now put codeigniter package in myci. Next you need to add this statment to index.php

myci/
    /system
    /application
    /index.php

require_once('../wp-load.php');

现在您需要扩展 site_url code> base_url like this

Now you need to extend site_url and base_url like this

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

如何使用:

现在你可以这样访问它。希望它有帮助

Now you can access it like this. Hope it helps

http://www.domain.com/myci/index.php/controllername/method

注意index.php之前的文件夹名称

Note folder name before index.php

这篇关于Wordpress Codeigniter集成:如何替换CI上的site_url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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