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

CodeIgniter controller always calling index function

每当我尝试添加一个新控制器并通过 URL 访问各种 public 函数时,而不是仅重定向到 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";    
    }  
}

test是控制器 当输入 URL "..../test/"
输出是

is in Index

当输入 URL "..../test/c/"
输出是

is in Index

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

is in Index

代码在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."/";
}