【发布时间】:2018-11-30 22:47:18
【问题描述】:
我有一个名为 Collection 的类,它有两个名为 Index 和 Cars 的方法。
在我的控制器的基本格式中,它看起来像这样;
class Collection extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
}
public function index(){
$data = array(
'title' => 'Index Page'
);
$this->load->view('template/Header');
$this->load->view('collection/index', $data);
$this->load->view('template/Footer');
}
public function cars(){
$data = array(
'title' => 'Cars Page'
);
$this->load->view('template/Header');
$this->load->view('collection/list_of_cars', $data);
$this->load->view('template/Footer');
}
}
URI 如下所示;
example.com/collection/cars
这就是我想要的,cars 方法被处理,list_of_cars 视图照常显示。
但是我注意到,如果我在 URL 中添加另一个参数,例如
example.com/collection/cars/something
事实上,我可以根据需要添加任意数量的附加 URI 参数,但仍然不会出现 404 错误。
页面只是重新加载 - 它不应该因为该页面不存在而显示 404 错误吗?
感谢任何建议。
【问题讨论】:
-
您给出的参数被视为您正在访问的方法的参数,这意味着如果您像这样
example.com/collection/cars/something给出,您可以在您的cars方法中访问这个参数像这样public function cars($param){ echo $param;}跨度> -
不知道为什么你觉得这应该是 404,因为参数被忽略并且控制器/方法做了它应该做的事情。但是如果 404 是你想要的,@pradeep 已经给了你一个很好的答案。
-
如果我访问 URI
example.com/collection/cars/something/blah/blah,我应该不会看到 404 页面,因为 URI 不存在?
标签: php codeigniter http-status-code-404 codeigniter-3