【问题标题】:Codeigniter controller function always loads the index/home even accessing other controller functionCodeigniter 控制器功能始终加载索引/主页,即使访问其他控制器功能
【发布时间】:2013-11-16 02:19:12
【问题描述】:

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

配置.php

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

routes.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 wordpress codeigniter


    【解决方案1】:

    我认为您的第二个选项应该有效,我认为您需要执行以下操作:
    在 route.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');
        }
    
        }
        ?>
    


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

    【讨论】:

      【解决方案2】:

      看看你的配置文件

      config.php

      并更改此 uri_protocol 行 FROM:

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

      到这里:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-25
        相关资源
        最近更新 更多