php - CodeIgniter Controller 总是调用索引函数

标签 php html codeigniter php-5.5

每当我尝试添加一个新 Controller 并通过 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";    
    }  
}

测试是 Controller 当输入 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."/$1";
}

关于php - CodeIgniter Controller 总是调用索引函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31218898/

相关文章:

php - 如何处理 HTML 电子邮件中的长链接

html - 如果我将它用于我的布局,我的网站是否可以与不支持 html5 的下游浏览器一起使用?

javascript - Jquery Accordion 选项卡单击按钮时不会关闭

javascript - 在按钮的onclick监听器中获取父 View 的数据

php - 在 Codeigniter 中编辑记录时加载 View

php - 如何使用codeigniter中的内连接获取特定数据?

php - 如何防止在 codeigniter 中多次登录

php - 来自 GoDaddy 的电子邮件在 Gmail 中显示为 'via'

php - .htaccess 重写规则在 Mac 上无法正常工作

php - 如何生成好的盐——我的函数是否足够安全?