Quantcast
Channel: 周曙光的网络日志
Viewing all articles
Browse latest Browse all 114

安装使用RESTful 框架SLIM笔记

$
0
0
RESTful API框架有很多,其他语言不熟悉,我就找了PHP的。由于SLIM的有中文文档,阅读起来速度快许多,加之这篇文章里有非常易懂的示例,于是选了SLIM

相关框架:

  1. http://www.golaravel.com是一个PHP框架,内置名为LUMEN的 RESTful API框架,有中文文档,http://lumen.golaravel.com/docs/ 
  2. https://apigility.org/ 是基于ZEND框架的 RESTful API框架 。
  3. https://github.com/anandkunal/ToroPHP Toro is a PHP router for developing RESTful web applications and APIs. It is designed for minimalists who want to get work done. 
  4. https://github.com/yiisoft/yii2/ Yii PHP Framework Version 2 ,a modern PHP framework designed for professional Web development.

SLIM依赖composer来安装,不用composer安装还蛮困难的,没找到教程。经过一翻折腾后,我找到简便的安装方式了。


先去 https://getcomposer.org  下载  composer.phar

composer.phar 是一个PHP的压缩包,可直接运行,不需要想办法解开。



php composer.phar require slim/slim "^3.0"

代替 https://github.com/slimphp/Slim的说明书中提到的:

$ composer require slim/slim "^3.0"

这样相关的依赖包都安装上了:

$ php composer.phar require slim/slim "^3.0"
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing container-interop/container-interop (1.1.0)
    Loading from cache

  - Installing nikic/fast-route (v1.0.1)
    Loading from cache

  - Installing psr/http-message (1.0.1)
    Loading from cache

  - Installing pimple/pimple (v3.0.2)
    Loading from cache

  - Installing slim/slim (3.5.0)
    Downloading: 100%         

Writing lock file
Generating autoload files

gongzuola:myfavor.link zola$ 

这样就安装好了。

把sample 文件夹里的index.php 和 .htaccess复制到根目录下就可以测试了。

要让API工作起来,就需要写对应的SQL语句,实现CRUD操作了。CRUD操作是对数据库进行creat、read、update、delete操作的意思。

Viewing all articles
Browse latest Browse all 114

Trending Articles