CodeIgniter控制器总是调用索引函数

时间:2015-07-04 09:03:57

标签: php html codeigniter php-5.5

每当我尝试添加新控制器并通过URL访问各种公共函数时,不仅仅是重定向到index()函数而不是根据URL请求访问函数

示例代码

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

class courses extends CI_Controller
{    
    public function __construct()    
    {    
        parent::__construct();
        $this->load->model('user_model');
        define('CurrPage', 'Courses');
    }    
    public function index()
    {
        echo "is in Index";    
    }    
    public function categoryInfo()
    {
        echo "is in cat";    
    }

    public function c()
    {
        echo "is in c";    
    }  
}

测试是控制器 当输入URL“.... / test /”时
输出

  

在索引

当输入网址“.... / test / c /”时
输出

  

在索引

当输入URL“.... / test / categoryInfo /”时
输出

  

在索引

config / routes.php中的代码

  $route['default_controller'] = "home";
  $route['404_override'] = 'courses';  
  $route['v/(:any)']= "video_single/index"; 
  $route['userInfo/(:any)']= "userInfo/index";

1 个答案:

答案 0 :(得分:0)

尝试将此添加到config / routes.php

$controllers = array('test' );
foreach($controllers as $controller) {
    $route[$controller] = $controller."/index";
    $route[$controller."/(:any)"] = $controller."/$1";
}