fxu*_*ser 1 php controller codeigniter function call
我有一个名为Categories的控制器和一个名为index的函数,带有1个参数$ cat_id
所以它看起来像这样:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class categories extends CI_Controller {
function __construct(){
parent::__construct();
}
public function index($cat_id = null){
}
}
Run Code Online (Sandbox Code Playgroud)
当我从浏览器中调用它时,问题就来了......我使用这个:
http://www.mysite.dev/categories/12311323
Run Code Online (Sandbox Code Playgroud)
但返回404错误页面
相反,如果我使用
http://www.mysite.dev/categories/index/12313131
Run Code Online (Sandbox Code Playgroud)
会工作得很好......
我怎样才能确保索引函数的URL中不需要索引?
默认的CodeIgniter路由是/ controller/function/argument.要指定参数,您需要先指定该函数.如果要在没有该函数的情况下指定参数,则需要定义自定义路径.将此行添加到路由配置文件中应该可以执行您想要的操作.
$route['categories/(:num)'] = "categories/index/$1";
Run Code Online (Sandbox Code Playgroud)