Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix routing when no default route has been specified. Fixes #1758 #1764

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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