Skip to content

Commit 312f367

Browse files
authored
Merge pull request #884 from kenjis/docs-add-locale-routes
docs: add how to use locale routes
2 parents a2a5b0d + d225640 commit 312f367

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

docs/customization/route_config.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Customizing Routes
22

3-
If you need to customize how any of the auth features are handled, you will likely need to update the routes to point to the correct controllers. You can still use the `service('auth')->routes()` helper, but you will need to pass the `except` option with a list of routes to customize:
3+
## Change Some Routes
4+
5+
If you need to customize how any of the auth features are handled, you will likely need to update the routes to point to the correct controllers.
6+
7+
You can still use the `service('auth')->routes()` helper, but you will need to pass the `except` option with a list of routes to customize:
48

59
```php
610
service('auth')->routes($routes, ['except' => ['login', 'register']]);
@@ -12,3 +16,49 @@ Then add the routes to your customized controllers:
1216
$routes->get('login', '\App\Controllers\Auth\LoginController::loginView');
1317
$routes->get('register', '\App\Controllers\Auth\RegisterController::registerView');
1418
```
19+
20+
After customization, check your routes with the [spark routes](https://codeigniter.com/user_guide/incoming/routing.html#spark-routes) command.
21+
22+
## Use Locale Routes
23+
24+
You can use the `{locale}` placeholder in your routes
25+
(see [Locale Detection](https://codeigniter.com/user_guide/outgoing/localization.html#in-routes)).
26+
27+
```php
28+
$routes->group('{locale}', static function($routes) {
29+
service('auth')->routes($routes);
30+
});
31+
```
32+
33+
The above code registers the following routes:
34+
35+
```text
36+
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
37+
| Method | Route | Name | Handler | Before Filters | After Filters |
38+
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
39+
| GET | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerView | | toolbar |
40+
| GET | {locale}/login | login | \CodeIgniter\Shield\Controllers\LoginController::loginView | | toolbar |
41+
| GET | {locale}/login/magic-link | magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::loginView | | toolbar |
42+
| GET | {locale}/login/verify-magic-link | verify-magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::verify | | toolbar |
43+
| GET | {locale}/logout | logout | \CodeIgniter\Shield\Controllers\LoginController::logoutAction | | toolbar |
44+
| GET | {locale}/auth/a/show | auth-action-show | \CodeIgniter\Shield\Controllers\ActionController::show | | toolbar |
45+
| POST | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerAction | | toolbar |
46+
| POST | {locale}/login | » | \CodeIgniter\Shield\Controllers\LoginController::loginAction | | toolbar |
47+
| POST | {locale}/login/magic-link | » | \CodeIgniter\Shield\Controllers\MagicLinkController::loginAction | | toolbar |
48+
| POST | {locale}/auth/a/handle | auth-action-handle | \CodeIgniter\Shield\Controllers\ActionController::handle | | toolbar |
49+
| POST | {locale}/auth/a/verify | auth-action-verify | \CodeIgniter\Shield\Controllers\ActionController::verify | | toolbar |
50+
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
51+
```
52+
53+
If you set the global filter in the **app/Config/Filters.php** file, you need to
54+
update the paths for `except`:
55+
56+
```php
57+
public $globals = [
58+
'before' => [
59+
// ...
60+
'session' => ['except' => ['*/login*', '*/register', '*/auth/a/*']],
61+
],
62+
// ...
63+
];
64+
```

0 commit comments

Comments
 (0)