Skip to content

404 Error in pathinfo mode #1965

Description

@viosion

name: Bug report
about: Help us improve the framework by reporting bugs!


Describe the bug
When set uriProtocol = 'Pathinfo'
Close debug, got 404 error;

line 578 in Router.php

// '/home/index' $segments = [0=>'', 1=>'home', 2=>'index']
protected function validateRequest(array $segments)
{
$segments = array_filter($segments); // $segments = [1=>'home', 2=>'index']

Because array_filter() gets the result array, the index is not updated. So pathinfo '/home/index'([0=>'', 1=>home, 2=>index]) gets [1=>home, 2=>index], there is no $segments[0]; Controller cannot be found, resulting in 404;

line 587 in Router.php
`

$this->directory . ucfirst($this->translateURIDashes === true ? str_replace('-', '_', $segments[0]) : $segments[0]

`
ErrorException
Undefined offset: 0
SYSTEMPATH/Router/Router.php at line 587

Then add a line below:
$segments = array_filter($segments);
$segments = array_values($segments);
May solve this problem;

CodeIgniter 4 version
Codeigniter 4.0.0-beta.2

Affected module(s)
Router

Expected behavior, and steps to reproduce if appropriate

Context

  • OS: [Mac OS 10.14.4]
  • Web server [Nginx 1.13.2]
  • PHP version [7.2.14]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions