Skip to content

Commit

Permalink
Merge pull request #1764 from codeigniter4/routeplaceholders
Browse files Browse the repository at this point in the history
Fix routing when no default route has been specified. Fixes #1758
  • Loading branch information
lonnieezell authored Feb 27, 2019
2 parents 9553ead + bdbc6a4 commit 4d06fa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
5 changes: 3 additions & 2 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ public function autoRoute(string $uri)
*/
protected function validateRequest(array $segments)
{
$segments = array_filter($segments);

$c = count($segments);
$directory_override = isset($this->directory);

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

if (! is_file(APPPATH . 'Controllers/' . $test . '.php') && $directory_override === false && is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0]))
)
if (! is_file(APPPATH . 'Controllers/' . $test . '.php') && $directory_override === false && is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0])))
{
$this->setDirectory(array_shift($segments), true);
continue;
Expand Down
20 changes: 7 additions & 13 deletions user_guide_src/source/tutorial/static_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ code.

::

<?php namespace App\Controllers;
use CodeIgniter\Controller;
<?php namespace App\Controllers;
use CodeIgniter\Controller;

class Pages extends Controller {

public function index()
{
return view('welcome_message');
}
public function index()
{
return view('welcome_message');
}

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

Set the default controller to run your new method:

::

$routes->setDefaultController('Pages/showme');

Add the following line, **after** the route directive for '/'.

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

.. image:: ../images/tutorial1.png
:align: center
:align: center

0 comments on commit 4d06fa2

Please sign in to comment.