脚本宝典收集整理的这篇文章主要介绍了php route 路由转发类库 支持composer加载,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
php路由转发类库 支持composer加载
install
1.添加以下内容至PRoject目录composer.json
添加仓库
"repositories": {
"packagist": {
"tyPE": "composer",
"url": "https://packagist.phpcomposer.COM"
},
"croute": {
"type": "vcs",
"url": "git@github.com:luyunhua/croute.git"
}
}
添加依赖
"require": {
"php": ">=5.5.9",
"luyunhua/croute": "dev-master"
}
2.更新依赖
composer update
using
此处假设大家的php项目支持自动加载,这样你在使用路由分发器的时候将无需在include类库等源文件等操作
nginx 配置
配置server
server {
listen 82;
#listen somename:8080;
server_name _;
index index.php;
try_files $uri
$uri/
@rewrite;
location @rewrite {
rewrite ^(.*)$ /index.php?_url=$1;
}
location ~ .php$ {
root /VAR/wwwroot/mframe;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_SCRIPT_NAME;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.htML;
location = /50x.html {
root /usr/share/nginx/html;
}
}
nginx 将php请求转发至82端口处理
location ~ .php$ {
Proxy_pass http://127.0.0.1:82;
}
核心代码演示
<?php
/**
* Created by luyh@59Store.com.
* User: luyh
* Date: 16/5/30
* Time: 下午1:42
* File: index.php
*/
include __DIR__ . '/boots/autoload.php';
$fileRoute = new TomatoRouteFileRoute();
$fileRoute->get('/myroute/abc/d+' ,'AppCtrlDefaultController@index');
$fileRoute->post('/myroute/post/w+/d' ,'AppCtrlDefaultController@index2');
$dispatcher = new TomatoRouteDispatcher($fileRoute);
$dispatcher->run();
以上是脚本宝典为你收集整理的php route 路由转发类库 支持composer加载全部内容,希望文章能够帮你解决php route 路由转发类库 支持composer加载所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。