Skip to content

Commit 4d06fa2

Browse files
authored
Merge pull request #1764 from codeigniter4/routeplaceholders
Fix routing when no default route has been specified. Fixes #1758
2 parents 9553ead + bdbc6a4 commit 4d06fa2

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

system/Router/Router.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ public function autoRoute(string $uri)
561561
*/
562562
protected function validateRequest(array $segments)
563563
{
564+
$segments = array_filter($segments);
565+
564566
$c = count($segments);
565567
$directory_override = isset($this->directory);
566568

@@ -571,8 +573,7 @@ protected function validateRequest(array $segments)
571573
$test = $this->directory . ucfirst($this->translateURIDashes === true ? str_replace('-', '_', $segments[0]) : $segments[0]
572574
);
573575

574-
if (! is_file(APPPATH . 'Controllers/' . $test . '.php') && $directory_override === false && is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0]))
575-
)
576+
if (! is_file(APPPATH . 'Controllers/' . $test . '.php') && $directory_override === false && is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0])))
576577
{
577578
$this->setDirectory(array_shift($segments), true);
578579
continue;

user_guide_src/source/tutorial/static_pages.rst

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ code.
3131

3232
::
3333

34-
<?php namespace App\Controllers;
35-
use CodeIgniter\Controller;
34+
<?php namespace App\Controllers;
35+
use CodeIgniter\Controller;
3636

3737
class Pages extends Controller {
3838

39-
public function index()
40-
{
41-
return view('welcome_message');
42-
}
39+
public function index()
40+
{
41+
return view('welcome_message');
42+
}
4343

4444
public function showme($page = 'home')
4545
{
@@ -204,12 +204,6 @@ The only uncommented line there to start with should be:::
204204
This directive says that any incoming request without any content
205205
specified should be handled by the ``index`` method inside the ``Home`` controller.
206206

207-
Set the default controller to run your new method:
208-
209-
::
210-
211-
$routes->setDefaultController('Pages/showme');
212-
213207
Add the following line, **after** the route directive for '/'.
214208

215209
::
@@ -236,4 +230,4 @@ method in the pages controller? Awesome!
236230
You should see something like the following:
237231

238232
.. image:: ../images/tutorial1.png
239-
:align: center
233+
:align: center

0 commit comments

Comments
 (0)