Wordpress Codeigniter Integration: How to replace site_url on CI?

南笙酒味 提交于 2020-01-15 10:54:50

问题


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


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/19920691/wordpress-codeigniter-integration-how-to-replace-site-url-on-ci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!