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


CodeIgniter controller always calling index function

每当我试图添加新的控制器并通过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/"时
输出为

在索引中

当键入URL"…./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";

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

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