flaviojr/silex-controller-provider
Composer 安装命令:
composer require flaviojr/silex-controller-provider
包简介
Controller provider for silex applications
README 文档
README
Controller provider for silex
What is this?
This provider contains the logic to load your controllers dynamically, registering them in you Silex Applications. With this, you no longer needs to manually register each one of your controllers, passing their respective dependencies.
Usage
To install it:
$ composer require "flaviojr/silex-controller-provider":"1.0"
To use this provider, you simply need to register it within your application:
//Don't forget to register this provider first $app->register(new Silex\Provider\ServiceControllerServiceProvider); $app->register(new Sneek\Providers\ControllerProvider('controller-dir', 'Your-root-namespace'[, 'your-namespace-mirror']));
- The first parameter indicate where your controller files are.
- The second one is the root namespace from where your controllers are. For example, if your controller namespace is
App\Controllers\HomeController, then the value to be passed is the string 'App'. - The last parameter is optional, you should use it if your root namespace isn't the name of your root directory. For example,
if you have a folder structure like this:
src/Controllers/CoffeeController, having the namespaceApp\Controllers\CoffeeControlleryou have to pass the 'src' string, so that the provider know that 'src' is equivalent to 'App' in this case.
Using the registered controllers
The provider register your controllers using their namespaces as index. To access they in your routes, you just need to pass their namespace followed by the method you are trying to access.
$app->get('/', 'App\Controllers\CoffeeController:index');
Notes
- You don't have to worry about your controller dependencies, the provider will recursively resolve each one of them.
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-24