Wordpress Codeigniter Integration: How to replace

2019-08-04 06:34发布

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

Here is my code on CI :
config.php

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

my_helper.php

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

It works fine and show http://www.domain.com when I use

<?php
echo site_url();
?>

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

2条回答
劫难
2楼-- · 2019-08-04 07:23

@raheel shan Where to add :

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);
}
}
查看更多
唯我独甜
3楼-- · 2019-08-04 07:36

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.

in wordpress directory create a folder called myci

wordpress/
         /myci

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');

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

How to use :

Now you can access it like this. Hope it helps

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

Note folder name before index.php

查看更多
登录 后发表回答