【问题标题】:CodeIgniter Missing Arguments Redirect to 404CodeIgniter 缺少参数重定向到 404
【发布时间】:2012-07-10 18:04:04
【问题描述】:

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

我不想改变:

public function index(){...}

收件人:

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

【问题讨论】:

  • 想解释一下为什么不呢?这将是最优雅、最灵活的解决方案。如果变量为空,则重定向。否则你需要使用路由,但是你必须为每个控制器更新路由文件......

标签: php codeigniter redirect


【解决方案1】:

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

在 routes.php 中

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

在apple.php中

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 2014-06-12
    • 2021-01-22
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    相关资源
    最近更新 更多