rawphp / raw-router
RawRouter 是一个简单的路由器,由 RawPHP 框架和其他应用程序使用。
dev-master / 0.x-dev
2014-12-22 21:37 UTC
Requires
- php: >=5.4.0
- rawphp/raw-dispatcher: dev-master
- rawphp/raw-support: dev-master
Requires (Dev)
- phpunit/phpunit: 4.2.5
- rawphp/raw-code-standards: 1.*@dev
- satooshi/php-coveralls: dev-master
Suggests
- rawphp/raw-request: RawRouter makes it easier in creating urls and routes for the router.
This package is auto-updated.
Last update: 2024-09-20 08:00:27 UTC
README
包特性
- 简单易用的路由器
- MVC 风格的路由
安装
Composer
RawRouter 通过 Composer/Packagist 提供。
将 "rawphp/raw-router": "0.*@dev"
添加到 composer.json 中的 require 块,然后运行 composer install
。
{ "require": { "rawphp/raw-router": "0.*@dev" } }
您也可以简单地从命令行运行以下命令
composer require rawphp/raw-router "0.*@dev"
存档包
或者,只需将 RawRouter 文件夹的内容复制到 PHP 的 include_path
设置中。如果您不熟悉 git 或只想获取存档包,请点击 GitHub 页面顶部的 'zip' 按钮。
基本用法
<?php use RawPHP\RawRouter\Router; // configuration $config = array( 'default_controller' => 'home', // the controller that will handle requests if the requested controller is not found 'default_action' => 'index', // the default action (method) to call if the requested action is not found 'namemspace' => 'RawPHP\\RawRouter\\Controllers\\', // the controllers namespace, leave empty if namespaces are not used ); // get new router instance $router = new Router( ); // initialise router $router->init( $config ); // example request // http://example.com/users/get/1 $route = 'users/get'; // the route must be in one of the following formats [ controller, controller/action, controller/action/param/param/... ] $params = array( 1 ); // array of values to be passed to the action method in the correct order // create controller $controller = $router->createController( $route, $params ); // run controller action $controller->run( );
许可证
本软件包采用 MIT 许可。请参阅 LICENSE 以获取有关软件可用性和分发的信息。
贡献
请将错误报告、建议和拉取请求提交到 GitHub 问题跟踪器。
变更日志
22-09-2014
- 在 PHP 5.3 上测试
20-09-2014
- 将 php 数组配置替换为 yaml
18-09-2014
- 为 Controller 添加了
loadView()
方法,可以加载 html 模板 - 添加了 LEController,它扩展了 Controller 并提供了语言功能。它可以加载用于在 html 模板中使用的不同语言翻译。
- 更新以支持最新的 rawphp/rawbase 包。
- 为 Controller 两个都添加了
init()
方法,以确保控制器得到适当的初始化。
17-09-2014
- 更新以支持最新的 rawphp/rawbase 包。
- 为 Action 添加了额外的钩子。
- 删除了构造函数,并在 Controller 中添加了新的
setAction( IAction )
方法。
14-09-2014
- 实现了钩子系统。
- 将 RawController 重命名为 Controller。
12-09-2014
- 将路由器构造函数的参数从单个参数更改为配置数组。
11-09-2014
- 初始代码提交