mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Move routes files back to Config folder for now, and drop the modulesPath config setting.
This commit is contained in:
parent
520a0a2378
commit
0604b40afa
@ -26,7 +26,7 @@ class Routing extends BaseRouting
|
||||
* Default: APPPATH . 'Config/Routes.php'
|
||||
*/
|
||||
public array $routeFiles = [
|
||||
APPPATH . 'Routes.php',
|
||||
APPPATH . 'Config/Routes.php',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -27,16 +27,6 @@ class Routing extends BaseConfig
|
||||
APPPATH . 'Routes.php',
|
||||
];
|
||||
|
||||
/**
|
||||
* When discovering routes within "modules", or namespaces other
|
||||
* than "App", this is the path relative to the module's root
|
||||
* directory.
|
||||
*
|
||||
* Default: 'Routes.php'
|
||||
* Legacy: 'Config/Routes.php'
|
||||
*/
|
||||
public string $modulePath = 'Routes.php';
|
||||
|
||||
/**
|
||||
* The default namespace to use for Controllers when no other
|
||||
* namespace has been specified.
|
||||
|
@ -94,12 +94,6 @@ class RouteCollection implements RouteCollectionInterface
|
||||
*/
|
||||
protected array $routeFiles = [];
|
||||
|
||||
/**
|
||||
* The path to the file that contains
|
||||
* the route definitions within "modules".
|
||||
*/
|
||||
protected string $modulePath;
|
||||
|
||||
/**
|
||||
* Defined placeholders that can be used
|
||||
* within the
|
||||
@ -269,7 +263,6 @@ class RouteCollection implements RouteCollectionInterface
|
||||
$this->override404 = $routing->override404;
|
||||
$this->autoRoute = $routing->autoRoute;
|
||||
$this->routeFiles = $routing->routeFiles;
|
||||
$this->modulePath = $routing->modulePath;
|
||||
$this->prioritize = $routing->prioritize;
|
||||
}
|
||||
|
||||
@ -327,12 +320,7 @@ class RouteCollection implements RouteCollectionInterface
|
||||
$routes = $this;
|
||||
|
||||
if ($this->moduleConfig->shouldDiscover('routes')) {
|
||||
if (empty($this->modulePath)) {
|
||||
log_message('warning', 'Routes module path is not set in Config/Routing.php.');
|
||||
return;
|
||||
}
|
||||
|
||||
$files = $this->fileLocator->search($this->modulePath);
|
||||
$files = $this->fileLocator->search('Config/Routes.php');
|
||||
|
||||
foreach ($files as $file) {
|
||||
// Don't include our main file again...
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace CodeIgniter\Commands\Utilities\Routes;
|
||||
|
||||
use Config\Routing;
|
||||
use CodeIgniter\Config\Services;
|
||||
use CodeIgniter\Filters\CSRF;
|
||||
use CodeIgniter\Filters\DebugToolbar;
|
||||
@ -52,7 +53,7 @@ final class FilterFinderTest extends CIUnitTestCase
|
||||
|
||||
private function createRouteCollection(array $routes = []): RouteCollection
|
||||
{
|
||||
$collection = new RouteCollection(Services::locator(), $this->moduleConfig);
|
||||
$collection = new RouteCollection(Services::locator(), $this->moduleConfig, new Routing());
|
||||
|
||||
$routes = ($routes !== []) ? $routes : [
|
||||
'users' => 'Users::index',
|
||||
|
@ -51,7 +51,6 @@ final class RouteCollectionTest extends CIUnitTestCase
|
||||
|
||||
$routerConfig = new \Config\Routing();
|
||||
$routerConfig->defaultNamespace = '\\';
|
||||
$routerConfig->modulePath = 'Config/Routes.php';
|
||||
|
||||
return (new RouteCollection($loader, $moduleConfig, $routerConfig))->setHTTPVerb('get');
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ final class RouterTest extends CIUnitTestCase
|
||||
|
||||
$routerConfig = new \Config\Routing();
|
||||
$routerConfig->defaultNamespace = '\\';
|
||||
$routerConfig->modulePath = 'Config/Routes.php';
|
||||
|
||||
$this->collection = new RouteCollection(Services::locator(), $moduleConfig, $routerConfig);
|
||||
|
||||
|
@ -105,7 +105,6 @@ Changes
|
||||
characters like ``(``, ``)``, etc., CodeIgniter didn't work. Since v4.4.0,
|
||||
this restriction has been removed.
|
||||
- **Config:** Routing settings have been moved to ``Config\Routing`` config file.
|
||||
- The default location for new projects Routes.php file has been moved to `app/Routes.php`. This can be modified in the `Config/Routing.php` file.
|
||||
|
||||
Deprecations
|
||||
************
|
||||
|
@ -154,8 +154,6 @@ the **Modules** config file, described above.
|
||||
When working with modules, it can be a problem if the routes in the application contain wildcards.
|
||||
In that case, see :ref:`routing-priority`.
|
||||
|
||||
By default, route files are named **Routes.php** and are located in the root directory of the module. You can change this by setting the ``$modulePath`` variable in the **Routing** config file to path to the file, relative to the module's root directory. For example, if you wanted to put your routes in a file named **Routes.php** in the module's ``Config`` directory, you would set the ``$modulePath`` variable to ``Config/Routes.php``.
|
||||
|
||||
Filters
|
||||
=======
|
||||
|
||||
|
@ -69,7 +69,6 @@ To clean up the routing system, the following changes were made:
|
||||
- New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file.
|
||||
- The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file.
|
||||
- The ``app/Config/Routes.php`` file was moved to ``app/Routes.php`` to make it easier to find. When upgrading, you can change the ``app/Config/Routing.php` file, ``$routeFiles`` property to point to the old location if you prefer.
|
||||
- Any module ``Routes.php`` files are expected to be in the namespace's root directory now. To adjust this to match the functionality of existing projects, you can cahnge the ``$modulePath`` property in ``app/Config/Routing.php`` to ``'Config/Routes.php'``.
|
||||
- The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``.
|
||||
|
||||
Config
|
||||
|
Loading…
x
Reference in New Issue
Block a user