定制 ecoal95/php-router 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ecoal95/php-router

最新稳定版本:v1.0.3

Composer 安装命令:

composer require ecoal95/php-router

包简介

Minimal routing library

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Contributors

Composer setup example

{
    "require": {
        "ecoal95/php-router": "dev-master"
    }
}

Usage

See the examples/ to see a basic example and remember to use the htaccess provided there!

Get urls

<a href="<?php echo $router->url('/users/username'); ?>">Username's profile</a>

Get the current url

$router->url();

Blog example

$router = new Router\Router('/blog');

$router->add('/', function() {
	echo 'homepage';
});

$router->add('/about', function() {
	echo 'about page';
});

$router->add('/([0-9]{4})', function($year) {
	echo $year . ' years active';
});

$router->add('/([0-9]{4})/([0-9]{2})', function ($year, $month) {
	echo 'archives from ' . $year . '/' . $month;
});

$router->add('/(.*)', function($slug) {
	// For example:
	if( Article::where('slug', '=', $slug)->first() ) {
		echo 'article';
	} else {
		echo '404';
	}
});

$router->post('/posts/create', function() {
	echo 'post created';
});

$router->post('/posts/update/([0-9]+)', function($post_id){
	// Update post with id = $post_id
});

// compare url with all registered routes
$router->route();

统计信息

  • 总下载量: 1.02k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 27
  • Watchers: 7
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-03