githubjeka / rest-yii2
Yii 2 Rest Api 模板
dev-master
2017-12-23 10:34 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: ~2.0.6
- yiisoft/yii2-bootstrap: ~2.0.0
- yiisoft/yii2-swiftmailer: ~2.0.0 || ~2.1.0
Requires (Dev)
- codeception/base: ^2.2.3
- codeception/verify: ~0.3.1
- yiisoft/yii2-debug: ~2.0.0
- yiisoft/yii2-faker: ~2.0.0
- yiisoft/yii2-gii: ~2.0.0
This package is auto-updated.
Last update: 2024-09-19 17:36:27 UTC
README
安装
通过 Composer 安装
如果您没有 Composer,可以通过在 getcomposer.org 的 说明 中进行操作来安装它。
然后,您可以使用以下命令安装应用程序
composer global require "fxp/composer-asset-plugin:~1.0.0"
composer create-project --prefer-dist -s dev "githubjeka/rest-yii2" .
入门
安装应用程序后,您必须执行以下步骤以初始化安装的应用程序。您只需执行一次即可。
- 运行命令
php init --env=Development
以特定环境初始化应用程序。 - 创建一个新的数据库,并相应地调整
common/config/main-local.php
中的components['db']
配置。 - 使用控制台命令
php yii migrate
应用迁移。这将创建应用程序运行所需的所有表。 - 设置您的 Web 服务器的文档根目录
对于 rest /path/to/yii-application/rest/web/
,并使用 URL https:///
作为后端 /path/to/yii-application/backend/web/
,并使用 URL http://backend-localhost/
使用 demo/demo
登录到应用程序,URL 为 https:///v1/user/login。有关更多信息,请参阅 /rest/config/main.php
URL 规则
可用的 API
// version 1 OPTIONS /index.php?r=v1/user/login POST /index.php?r=v1/user/login OPTIONS /index.php?r=v1/posts GET /index.php?r=v1/posts GET /index.php?r=v1/posts/ID POST /index.php?r=v1/posts PUT /index.php?r=v1/posts/ID DELETE /index.php?r=v1/posts/ID OPTIONS /index.php?r=v1/comments GET /index.php?r=v1/comments GET /index.php?r=v1/comments/ID POST /index.php?r=v1/comments PUT /index.php?r=v1/comments/ID DELETE /index.php?r=v1/comments/ID //version 2 OPTIONS /index.php?r=v2/user/login POST /index.php?r=v2/user/login
您可以从 URL 中隐藏 index.php
。有关详情,请参阅 server.md