Codeigniter控制器功能总是加载索引/ home甚至访问其他控制器功能

时间:2013-11-16 02:19:12

标签: php wordpress codeigniter

我试图在我的系统中集成codeigniter和wordpress,但确实如此。通过在我的codeigniter root中放置wordpress似乎正在工作,但是在config,index和route.php中进行了调整。我现在可以在我的codeigniter视图文件中使用wp函数,但是,会出现问题。每当我访问控制器中的其他功能时,它都会重定向到控制器的索引功能。这有什么问题? wp和ci url之间是否存在冲突,或者可能还有其他原因?如果有,我怎么能解决这个?这是我的代码。谢谢你的帮助。

的config.php

$config['index_page'] = 'index.php';$config['index_page'] = '';

routes.php文件

默认路由正常

来自:$route['default_controller'] = "welcome";

     $route['404_override'] = '';

以下任何选项都会导致上述问题

to:3个路由选项

选项1:

# Option 1 - Use this section for a normal CI site
# with WP in its own folder

$route['default_controller'] = "ci_pages";
$route['(:any)'] = "wp_pages/$1";
$route['(:any)'] = "ci_pages/$1";
$route['404_override'] = '';

选项2:

# Option 2 - Use this section for a blended CI/WP site
# with selected WP pages routed to eppear in the web root
# Any WP route outside the WP folder must be set up as a CI route.

$route['default_controller'] = "ci_pages";
$route['(:any)'] = "ci_pages/$1";
$route['sample-page'] = "wp_pages/$1";
$route['404_override'] = '';

选项3:

 # Option 3 - Use this section for a CI site where WP is only
 # for content management and does not display its own pages
 # through CI routing.
 $route['default_controller'] = "ci_pages";
 $route['(:any)'] = "ci_pages/$1";
 $route['404_override'] = ''; 

controller:ci_pages.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CI_Pages extends CI_Controller
{

public function index()
{
  $this->load->view('home');

}

public function test()
{
    $this->load->view('test');
}

}
?>

2 个答案:

答案 0 :(得分:0)

我认为您的第二个选项应该可行,我认为您需要执行以下操作:
在route.php中

$route['default_controller'] = "ci_pages";
$route['(:any)'] = "ci_pages/index/$1";
$route['sample-page'] = "wp_pages/$1";
$route['404_override'] = '';


controller:ci_pages.php

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class CI_Pages extends CI_Controller
    {

    public function index()
    {
        $this->load->helper('url');
        $array_segments = $this->uri->segment_array();      
        if( isset( $array_segments[1] ) ) {
            $function_name = $array_segments[1];
            $this->{$function_name}();
        } 
    }

    public function home()
    {
        $this->load->view('home');
    }

    public function test()
    {
        $this->load->view('test');
    }

    }
    ?>

希望这可能对你有用我还没有测试过。但这里的想法是你只需要从索引函数路由到你的函数

答案 1 :(得分:0)

看看您的配置文件

  

config.php

并从以下位置更改此uri_protocol行:

  

$ config ['uri_protocol'] ='QUERY_STRING';

对此:

  

$ config ['uri_protocol'] ='REQUEST_URI';