https://github.com/yiisoft/file-router
Convention-based file structure router
https://github.com/yiisoft/file-router
convention filesystem optionalforframeworkannounce router routing structure yii3
Last synced: about 2 months ago
JSON representation
Convention-based file structure router
- Host: GitHub
- URL: https://github.com/yiisoft/file-router
- Owner: yiisoft
- License: bsd-3-clause
- Created: 2023-12-26T13:37:31.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-18T14:08:25.000Z (over 1 year ago)
- Last Synced: 2024-05-21T10:33:26.145Z (over 1 year ago)
- Topics: convention, filesystem, optionalforframeworkannounce, router, routing, structure, yii3
- Language: PHP
- Homepage: https://www.yiiframework.com
- Size: 43.9 KB
- Stars: 5
- Watchers: 16
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
Yii File Router
[](https://packagist.org/packages/yiisoft/file-router)
[](https://packagist.org/packages/yiisoft/file-router)
[](https://github.com/yiisoft/file-router/actions?query=workflow%3Abuild)
[](https://codecov.io/gh/yiisoft/file-router)
[](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/file-router/master)
[](https://github.com/yiisoft/file-router/actions?query=workflow%3A%22static+analysis%22)
[](https://shepherd.dev/github/yiisoft/file-router)
[](https://shepherd.dev/github/yiisoft/file-router)
The package provides a convention-based router middleware that chooses controller based on its namespace and class name.
## Requirements
- PHP 8.1 or higher.
## Installation
The package could be installed with [Composer](https://getcomposer.org):
```shell
composer require yiisoft/file-router
```
## General usage
1. Add `\Yiisoft\FileRouter\FileRouter` to the list of middlewares in your application configuration, `web/params.php`:
```php
return [
'middlewares' => [
// ...
Router::class,
\Yiisoft\FileRouter\FileRouter::class,
// or
[
'class' => FileRouter::class,
'withNamespace()' => ['App'],
'withBaseControllerDirectory()' => ['Controller'],
],
// ...
]
];
```
2. [Configure the file router](docs/guide/en#configuration) for your needs.
> Note: `FileRouter` goes after regular `Router` to serve as a fallback in case explicitly defined route
is not found.
By default, the following structure of the app could be used assuming `App` points to `src` directory:
```
src
Controller
User
Profile
IndexController.php
BlogController.php
UserController.php
IndexController.php
```
Here's how it works:
- `GET /` → `IndexController::index()`
- `GET /user` → `UserController::index()`
- `POST /user` → `UserController::create()`
- `GET /user/blog/view` → `User/BlogController::view()`
- `GET /user/profile` → `User/Profile/IndexController::index()`
## Documentation
For additional information, check the following docs:
- Guide: [English](docs/guide/en/README.md), [Português - Brasil](docs/guide/pt-BR/README.md)
- [Internals](docs/internals.md)
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).
## License
The Yii File Router is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.
Maintained by [Yii Software](https://www.yiiframework.com/).
## Support the project
[](https://opencollective.com/yiisoft)
## Follow updates
[](https://www.yiiframework.com/)
[](https://twitter.com/yiiframework)
[](https://t.me/yii3en)
[](https://www.facebook.com/groups/yiitalk)
[](https://yiiframework.com/go/slack)