欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > php >内容正文

php

flight php 中文,PHP: composer的简单使用

发布时间:2024/9/3 php 30 豆豆
生活随笔 收集整理的这篇文章主要介绍了 flight php 中文,PHP: composer的简单使用 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

安装

$ sudo php -r "readfile('https://getcomposer.org/installer');" | php

$ sudo mv composer.phar /usr/local/bin/composer

使用

{

"name": "mikecao/flight",

"description": "Flight is a fast, simple, extensible framework for PHP. Flight enables you to quickly and easily build RESTful web applications.",

"homepage": "http://flightphp.com",

"license": "MIT",

"authors": [

{

"name": "Mike Cao",

"email": "mike@mikecao.com",

"homepage": "http://www.mikecao.com/",

"role": "Original Developer"

}

],

"require": {

"php": ">=5.3.0"

},

"autoload": {

"files": [ "flight/autoload.php", "flight/Flight.php" ]

},

"require-dev": {

"phpunit/phpunit": "~4.6"

}

}

注意 autoload。

$ cd /var/www/html

$ touch index.php

$ touch .htaccess

.htaccess内容如下:

RewriteEngine on

RewriteBase /

RewriteRule !\.(js|html|ico|gif|jpg|png|css)$ index.php

下载flight:

$ composer require mikecao/flight

看下目录结构:

和index.php同一级的composer.json的内容如下:

{

"require": {

"mikecao/flight": "^1.2"

}

}

编写index.php:

require 'vendor/autoload.php';

Flight::route('/', function(){

echo 'hello world!';

});

Flight::route('/foo', function(){

echo 'welcome to foo!';

});

Flight::start();

浏览器访问http://127.0.0.1、http://127.0.0.1/foo可以看到效果。

修改composer.json后

$ composer install

# 或者

$ composer update

总结

以上是生活随笔为你收集整理的flight php 中文,PHP: composer的简单使用的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。