beanmoss / annotroute
此软件包的最新版本(0.1)没有提供许可信息。
允许您在控制器上使用路由注解。
0.1
2014-07-08 19:15 UTC
Requires
- php: >=5.4.0
- doctrine/common: ~2.4
- illuminate/support: 4.2.*
This package is not auto-updated.
Last update: 2024-09-24 08:03:06 UTC
README
允许您在 Laravel 控制器上使用路由注解。
要将 annotroute 作为 Composer 包安装到 Laravel 4 中,只需在您的 composer.json 中添加以下内容
"beanmoss/annotroute": "dev-master"
..并运行 composer update
。安装完成后,您可以在 app/config/app.php
文件的 providers
数组中注册服务提供者。我强烈建议您在 Router 提供者之后注册它
'providers' => array( ... 'Beanmoss\Annotroute\AnnotrouteServiceProvider', )
以及对于 Facade
... 'AnnotRoute' => 'Beanmoss\Annotroute\Facade\AnnotRoute', ...
使用方法
<?php use Beanmoss\Annotroute\Annotation\Route as MyRoute; /** * @MyRoute(group={"prefix" = "home", "before" = "auth"}) */ class HomeController extends BaseController { /* |-------------------------------------------------------------------------- | Default Home Controller |-------------------------------------------------------------------------- | | You may wish to use controllers instead of, or in addition to, Closure | based routes. That's great! Here is an example controller method to | get you started. To route to this controller, just add the route: | | Route::get('/', 'HomeController@showWelcome'); | */ /** * @MyRoute(method="get", path="/") * @MyRoute(method="get", path="/welcome") */ public function showWelcome() { return View::make('hello'); } /** * @MyRoute( * method="get", * path="/test/{id}/{name}", * before = "", * name="test", * where={"id" = "[0-9]+","name" = "[a-z]+"} * ) */ public function test($id, $name) { return 'test' . $id . $name; } }
并在您的 routes.php 文件中的某个位置
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ AnnotRoute::generateRoute('HomeController');
就这样!如果您发现了一些错误,请告诉我。谢谢!此外,您可以帮助我测试这个;)