Skip to content

Commit 62b1e16

Browse files
authored
Document optional attribute paths and routes files (#8369)
Refs cakephp/cakephp#19711, cakephp/cakephp#19665.
1 parent 3b15f6f commit 62b1e16

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎docs/en/development/attribute-routing.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ That's it. The `#[Scope]` attribute sets a path prefix for all routes in
7474
the controller. The `#[Get]` attribute maps each action to a URL path and HTTP
7575
method.
7676

77+
The path argument can be omitted. Under `#[Scope('/articles')]`, `#[Get]`
78+
matches `/articles`; without a scope it matches `/`. Named options can still
79+
be supplied, for example `#[Post(name: 'create')]`.
80+
81+
### Applications Without a Routes File
82+
83+
For attribute-only routing, connect attributes in your application's `routes()`
84+
hook instead of **config/routes.php**:
85+
86+
```php
87+
// In src/Application.php
88+
use Cake\Routing\RouteBuilder;
89+
90+
public function routes(RouteBuilder $routes): void
91+
{
92+
$routes->connectAttributes();
93+
}
94+
```
95+
96+
When all routes are registered this way, **config/routes.php** can be omitted.
97+
If you also need file-based routes, call `parent::routes($routes)` before
98+
connecting attributes so the file is loaded first.
99+
77100
## Choosing Your Approach
78101

79102
You have three options for defining routes in CakePHP:

0 commit comments

Comments
 (0)