代码点火器控制器功能始终加载索引/主页,即使访问其他控制器功能也是如此


Codeigniter controller function always loads the index/home even accessing other controller function

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

配置.php

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

路线.php

默认路由工作正常

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

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

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

收件人: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'] = ''; 

控制器: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');
}
}
?>

我认为您的第二个选项应该有效,我认为您需要执行以下操作:
在路线上.php

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


控制器: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');
    }
    }
    ?>


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

看看你的配置文件

配置.php

并将此uri_protocol行从:

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

对此:

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