CodeIgniter缺少参数重定向至404


CodeIgniter Missing Arguments Redirect to 404

如果用户键入/apple/而不是/apple/1,也就是未定义的URL,则应重定向到404页面。然而,它进入控制器并输出Missing Argument1消息。

我不想改变:

public function index(){...}

收件人:

public function index($id = null){...}

嗯,我没有测试它,但你可以做:

在routes.php 中

$route['apple/(:any)'] = "apple";
$route['apple'] = "apple";

在apple.php中

function index()
{
  if(!$this->uri->segment(1))
  {
    show_404();
  }
}