Browse Source

Merge pull request #65 from yiichina/doc

merge from Doc
tags/2.0.16
cuiliang 7 years ago committed by GitHub
parent
commit
45363c1f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 76
      docs/guide-zh-CN/README.md
  2. 202
      docs/guide-zh-CN/input-form-javascript.md
  3. 22
      docs/guide-zh-CN/start-prerequisites.md
  4. 103
      docs/guide-zh-CN/tutorial-docker.md
  5. 211
      docs/guide-zh-CN/tutorial-yii-as-micro-framework.md

76
docs/guide-zh-CN/README.md

@ -9,15 +9,16 @@ Yii 2.0 权威指南
介绍(Introduction)
------------
------------------
* [关于 Yii(About Yii)](intro-yii.md)
* [从 Yii 1.1 升级(Upgrading from Version 1.1)](intro-upgrade-from-v1.md)
入门(Getting Started)
---------------
---------------------
* [你需要了解什么(What do you need to know)](start-prerequisites.md)
* [安装 Yii(Installing Yii)](start-installation.md)
* [运行应用(Running Applications)](start-workflow.md)
* [第一次问候(Saying Hello)](start-hello.md)
@ -28,7 +29,7 @@ Yii 2.0 权威指南
应用结构(Application Structure)
---------------------
------------------------------
* [结构概述(Overview)](structure-overview.md)
* [入口脚本(Entry Scripts)](structure-entry-scripts.md)
@ -45,7 +46,7 @@ Yii 2.0 权威指南
请求处理(Handling Requests)
-----------------
--------------------------
* [运行概述(Overview)](runtime-overview.md)
* [引导(Bootstrapping)](runtime-bootstrapping.md)
@ -58,7 +59,7 @@ Yii 2.0 权威指南
关键概念(Key Concepts)
------------
---------------------
* [组件(Components)](concept-components.md)
* [属性(Properties)](concept-properties.md)
@ -72,30 +73,31 @@ Yii 2.0 权威指南
配合数据库工作(Working with Databases)
----------------------
------------------------------------
* [数据库访问(Data Access Objects)](db-dao.md): 数据库连接、基本查询、事务和模式操作
* [查询生成器(Query Builder)](db-query-builder.md): 使用简单抽象层查询数据库
* [活动记录(Active Record)](db-active-record.md): 活动记录对象关系映射(ORM),检索和操作记录、定义关联关系
* [数据库迁移(Migrations)](db-migrations.md): 在团体开发中对你的数据库使用版本控制
* [Sphinx](https://github.com/yiisoft/yii2-sphinx/blob/master/docs/guide/README.md)
* [Sphinx](https://github.com/yiisoft/yii2-sphinx/blob/master/docs/guide-zh-CN/README.md)
* [Redis(yii2-redis)](yii2-redis.md): yii2-redis 扩展详解
* [MongoDB](https://github.com/yiisoft/yii2-mongodb/blob/master/docs/guide/README.md)
* [ElasticSearch](https://github.com/yiisoft/yii2-elasticsearch/blob/master/docs/guide/README.md)
* [MongoDB](https://github.com/yiisoft/yii2-mongodb/blob/master/docs/guide-zh-CN/README.md)
* [ElasticSearch](https://github.com/yiisoft/yii2-elasticsearch/blob/master/docs/guide-zh-CN/README.md)
接收用户数据(Getting Data from Users)
-----------------------
------------------------------------
* [创建表单(Creating Forms)](input-forms.md)
* [输入验证(Validating Input)](input-validation.md)
* [文件上传(Uploading Files)](input-file-upload.md)
* [收集列表输入(Collecting Tabular Input)](input-tabular-input.md)
* [多模型同时输入(Getting Data for Multiple Models)](input-multiple-models.md)
* [在客户端扩展 ActiveForm(Extending ActiveForm on the Client Side)](input-form-javascript.md)
显示数据(Displaying Data)
---------------
------------------------
* [格式化输出数据(Data Formatting)](output-formatting.md)
* [分页(Pagination)](output-pagination.md)
@ -107,20 +109,19 @@ Yii 2.0 权威指南
安全(Security)
--------
--------------
* [概述(Overview)](security-overview.md)
* [认证(Authentication)](security-authentication.md)
* [授权(Authorization)](security-authorization.md)
* [处理密码(Working with Passwords)](security-passwords.md)
* [加密(Cryptography)](security-cryptography.md)
* [视图安全(Views security)](structure-views.md#security)
* [客户端认证(Auth Clients)](https://github.com/yiisoft/yii2-authclient/blob/master/docs/guide/README.md)
* [客户端认证(Auth Clients)](https://github.com/yiisoft/yii2-authclient/blob/master/docs/guide-zh-CN/README.md)
* [安全领域的最佳实践(Best Practices)](security-best-practices.md)
缓存(Caching)
-------
-------------
* [概述(Overview)](caching-overview.md)
* [数据缓存(Data Caching)](caching-data.md)
@ -129,8 +130,8 @@ Yii 2.0 权威指南
* [HTTP 缓存(HTTP Caching)](caching-http.md)
RESTful Web 服务
--------------------
RESTful Web 服务(RESTful Web Services)
--------------------------------------
* [快速入门(Quick Start)](rest-quick-start.md)
* [资源(Resources)](rest-resources.md)
@ -144,15 +145,15 @@ RESTful Web 服务
开发工具(Development Tools)
-----------------
--------------------------
* [调试工具栏和调试器(Debug Toolbar and Debugger)](https://github.com/yiisoft/yii2-debug/blob/master/docs/guide/README.md)
* [使用 Gii 生成代码(Generating Code using Gii)](https://github.com/yiisoft/yii2-gii/blob/master/docs/guide/README.md)
* **TBD** [生成 API 文档(Generating API Documentation)](https://github.com/yiisoft/yii2-apidoc)
* [调试工具栏和调试器(Debug Toolbar and Debugger)](https://github.com/yiisoft/yii2-debug/blob/master/docs/guide-zh-CN/README.md)
* [使用 Gii 生成代码(Generating Code using Gii)](https://github.com/yiisoft/yii2-gii/blob/master/docs/guide-zh-CN/README.md)
* [生成 API 文档(Generating API Documentation)](https://github.com/yiisoft/yii2-apidoc)
测试(Testing)
-------
-------------
* [概述(Overview)](test-overview.md)
* [搭建测试环境(Testing environment setup)](test-environment-setup.md)
@ -163,39 +164,42 @@ RESTful Web 服务
高级专题(Special Topics)
--------------
-----------------------
* [高级应用模版(Advanced Project Template)](https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md)
* [高级应用模版(Advanced Project Template)](https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide-zh-CN/README.md)
* [从头构建自定义模版(Building Application from Scratch)](tutorial-start-from-scratch.md)
* [控制台命令(Console Commands)](tutorial-console.md)
* [核心验证器(Core Validators)](tutorial-core-validators.md)
* [Docker](tutorial-docker.md)
* [国际化(Internationalization)](tutorial-i18n.md)
* [收发邮件(Mailing)](tutorial-mailing.md)
* [性能优化(Performance Tuning)](tutorial-performance-tuning.md)
* [共享主机环境(Shared Hosting Environment)](tutorial-shared-hosting.md)
* [模板引擎(Template Engines)](tutorial-template-engines.md)
* [集成第三方代码(Working with Third-Party Code)](tutorial-yii-integration.md)
* [使用 Yii 作为微框架(Using Yii as a micro framework)](tutorial-yii-as-micro-framework.md)
小部件(Widgets)
-------
---------------
* 表格视图(GridView): **TBD** 链接到 demo 页
* 列表视图(ListView): **TBD** 链接到 demo 页
* 详情视图(DetailView): **TBD** 链接到 demo 页
* 活动表单(ActiveForm): **TBD** 链接到 demo 页
* Pjax: **TBD** 链接到 demo 页
* 菜单(Menu): **TBD** 链接到 demo 页
* LinkPager: **TBD** 链接到 demo 页
* LinkSorter: **TBD** 链接到 demo 页
* [Bootstrap 小部件(Bootstrap Widgets](https://github.com/yiisoft/yii2-bootstrap/blob/master/docs/guide/README.md)
* [jQuery UI 小部件(jQuery UI Widgets](https://github.com/yiisoft/yii2-jui/blob/master/docs/guide/README.md)
* [GridView](http://www.yiiframework.com/doc-2.0/yii-grid-gridview.html)
* [ListView](http://www.yiiframework.com/doc-2.0/yii-widgets-listview.html)
* [DetailView](http://www.yiiframework.com/doc-2.0/yii-widgets-detailview.html)
* [ActiveForm](http://www.yiiframework.com/doc-2.0/guide-input-forms.html#activerecord-based-forms-activeform)
* [Pjax](http://www.yiiframework.com/doc-2.0/yii-widgets-pjax.html)
* [Menu](http://www.yiiframework.com/doc-2.0/yii-widgets-menu.html)
* [LinkPager](http://www.yiiframework.com/doc-2.0/yii-widgets-linkpager.html)
* [LinkSorter](http://www.yiiframework.com/doc-2.0/yii-widgets-linksorter.html)
* [Bootstrap Widgets](https://github.com/yiisoft/yii2-bootstrap/blob/master/docs/guide-zh-CN/README.md)
* [jQuery UI Widgets](https://github.com/yiisoft/yii2-jui/blob/master/docs/guide-zh-CN/README.md)
助手类(Helpers)
-------
---------------
* [助手一览(Overview)](helper-overview.md)
* [Array 助手(ArrayHelper)](helper-array.md)
* [Html 助手(Html)](helper-html.md)
* [Url 助手(Url)](helper-url.md)

202
docs/guide-zh-CN/input-form-javascript.md

@ -0,0 +1,202 @@
在客户端扩展 ActiveForm
=====================
[[yii\widgets\ActiveForm]] 小部件附带一组用于客户端验证的 JavaScript 方法。
它的实现非常灵活,可以让你以不同的方式扩展它。
下面我们来看描述。
## ActiveForm 事件
ActiveForm 触发一系列专用事件。使用类似以下的代码,您可以订阅这些代码
事件并处理它们:
```javascript
$('#contact-form').on('beforeSubmit', function (e) {
if (!confirm("Everything is correct. Submit?")) {
return false;
}
return true;
});
```
在下文中,我们将查看可用的事件。
### `beforeValidate`
`beforeValidate` 是在验证整个表单之前触发的。
事件处理程序的签名应该是:
```javascript
function (event, messages, deferreds)
```
其中
- `event`: 一个 Event 对象。
- `messages`: 一个关联数组,其中键是属性ID,
值是相应属性的错误消息数组。
- `deferreds`: 一个 Deferred 对象数组。你可以使用 `deferreds.add(callback)`
来添加一个新的延迟验证。
如果处理程序返回一个布尔型 `false`,它将在此事件后停止进一步的表单验证。
结果 `afterValidate` 事件将不会被触发。
### `afterValidate`
`afterValidate` 是在验证整个表单后触发的。
事件处理程序的签名应该是:
```javascript
function (event, messages, errorAttributes)
```
其中
- `event`: 一个 Event 对象。
- `messages`: 一个关联数组,其中键是属性ID,
值是相应属性的错误消息数组。
- `errorAttributes`: 一个具有验证错误的属性数组。有关此参数的结构,
请参阅 `attributeDefaults`
### `beforeValidateAttribute`
`beforeValidateAttribute` 事件是在验证属性之前触发的。
事件处理程序的签名应该是:
```javascript
function (event, attribute, messages, deferreds)
```
其中
- `event`: 一个 Event 对象。
- `attribute`: 要验证的属性。 请参阅这个参数的 `attributeDefaults`
结构。
- `messages`: 可以为其添加指定属性的验证错误消息的数组。
- `deferreds`: 一个 Deferred 对象数组。你可以使用 `deferreds.add(callback)`
来添加一个新的延迟验证。
如果处理程序返回布尔型 `false`,它将停止进一步验证指定的属性。
结果,`afterValidateAttribute` 事件将不会被触发。
### `afterValidateAttribute`
`afterValidateAttribute` 事件在验证整个表单和每个属性后触发的。
事件处理程序的签名应该是:
```javascript
function (event, attribute, messages)
```
其中
- `event`: 一个 Event 对象。
- `attribute`: 该属性会被验证。有关此参数的结构,
请参阅 `attributeDefaults`
- `messages`: 可以为其添加指定属性的其他验证错误消息的
数组。
### `beforeSubmit`
`beforeSubmit` 是在所有验证通过后且提交表单之前触发的。
事件处理程序的签名应该是:
```javascript
function (event)
```
其中 `event` 是一个 Event 对象。
如果处理返回布尔型“false”,它将停止表单提交。
### `ajaxBeforeSend`
`ajaxBeforeSend` 事件是在发送用于基于AJAX的验证的AJAX请求之前触发的。
事件处理程序的签名应该是:
```javascript
function (event, jqXHR, settings)
```
其中
- `event`: 一个 Event 对象。
- `jqXHR`: 一个 jqXHR 对象
- `settings`: AJAX 请求的设置
### `ajaxComplete`
`ajaxComplete` 事件是在完成基于 AJAX 验证的 AJAX 请求后触发的。
事件处理程序的签名应该是:
```javascript
function (event, jqXHR, textStatus)
```
where
- `event`: 一个 Event 对象。
- `jqXHR`: 一个 jqXHR 对象
- `textStatus`: 请求的状态 ("success", "notmodified", "error", "timeout",
"abort", or "parsererror")。
## 通过 AJAX 提交表单
虽然可以在客户端或通过 AJAX 请求进行验证,但作为默认的正常请求
表单提交本身已完成。如果你想通过 AJAX 提交表单,你可以
通过以下方式处理表单的 `beforeSubmit` 事件做到这一点:
```javascript
var $form = $('#formId');
$form.on('beforeSubmit', function() {
var data = $form.serialize();
$.ajax({
url: $form.attr('action'),
type: 'POST',
data: data,
success: function (data) {
// 执行成功
},
error: function(jqXHR, errMsg) {
alert(errMsg);
}
});
return false; // 防止默认提交
});
```
要了解更多关于 jQuery `ajax()` 函数的信息,请参阅 [jQuery 文档](https://api.jquery.com/jQuery.ajax/)。
## 动态添加字段
在现代 Web 应用程序中,您经常需要在向用户显示表单后更改表单。
这可以例如在点击“加号”图标之后添加新的字段。
要为这些字段启用客户端验证,他们必须注册 ActiveForm JavaScript 插件。
您必须自行添加一个字段,然后将其添加到验证列表中:
```javascript
$('#contact-form').yiiActiveForm('add', {
id: 'address',
name: 'address',
container: '.field-address',
input: '#address',
error: '.help-block',
validate: function (attribute, value, messages, deferred, $form) {
yii.validation.required(value, messages, {message: "Validation Message Here"});
}
});
```
要从验证列表中删除一个字段,使它不被验证,您可以执行以下操作:
```javascript
$('#contact-form').yiiActiveForm('remove', 'address');
```

22
docs/guide-zh-CN/start-prerequisites.md

@ -0,0 +1,22 @@
# 你需要了解什么
Yii 的学习曲线并不像其他 PHP 框架那样陡峭,但仍然需要一些基础知识。
## PHP
Yii 是一个 PHP 框架,因此请确保您 [阅读并理解语言参考](http://php.net/manual/zh/langref.php)。
## 面向对象编程
对面向对象编程的基本理解是必需的。如果您不熟悉它,请选中其中一个
可用的教程,如 [tuts+](https://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762)。
请注意,您的应用程序越复杂,您需要学习的更高级的 OOP 概念才能成功
掌握这种复杂度。
## 命令行和 Composer
Yii 广泛使用了标准的 PHP 包管理器 [Composer](https://getcomposer.org/),因此请确保您阅读
并理解其指南。如果您不熟悉命令行,现在该开始尝试了。
一旦你学会了基础知识,你就永远不想在没有它的情况下工作。

103
docs/guide-zh-CN/tutorial-docker.md

@ -0,0 +1,103 @@
Yii 和 Docker
=============
对于开发和部署 Yii 应用程序可以使用 Docker 容器运行。容器就像一个轻量级的独立虚拟机,它将其服务映射到主机的端口,即在端口 80 上的容器中的Web服务器在您的(本地)主机上的端口 8888 上可用。
容器可以解决许多问题,例如在开发人员计算机和服务器上具有相同的软件版本,在开发时快速部署或模拟多服务器体系结构。
您可以在 [docker.com](https://www.docker.com/what-docker) 上阅读有关Docker容器的更多信息。
## 要求
- `docker`
- `docker-compose`
访问[下载页面](https://www.docker.com/community-edition)获取 Docker 工具。
## 安装
安装后,你应该可以运行 `docker ps` 并看到类似的输出:
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
```
这意味着您的Docker守护进程已启动并正在运行。
另外运行 `docker-compose version`,你的输出应该是这样的
```
docker-compose version 1.20.0, build unknown
docker-py version: 3.1.3
CPython version: 3.6.4
OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
```
使用 Compose,您可以配置管理您的应用程序所需的所有服务,例如数据库和缓存。
## 资源
- 基于 PHP 的 Yii 镜像可以在这里找到 [yii2-docker](https://github.com/yiisoft/yii2-docker)
- Docker 支持的 [yii2-app-basic](https://github.com/yiisoft/yii2-app-basic#install-with-docker)
- Docker 支持的 [yii2-app-advanced](https://github.com/yiisoft/yii2-app-advanced/pull/347) 正在开发中
## 用法
Docker的基本命令是:
docker-compose up -d
在后台启动堆栈中的所有服务
docker-compose ps
列出正在运行的服务
docker-compose logs -f
持续查看所有服务的日志
docker-compose stop
优雅地停止堆栈中的所有服务
docker-compose kill
立即停止堆栈中的所有服务
docker-compose down -v
停止并删除所有服务,**在不使用 host-volumes 时注意数据丢失**
在容器中运行命令
docker-compose run --rm php composer install
在新的容器中运行 composer 安装
docker-compose exec php bash
*运行中的* `php` 服务中执行 bash
## 高级主题
### Yii 框架测试
你可以按照[这里](https://github.com/yiisoft/yii2/blob/master/tests/README.md#dockerized-testing)描述的方式为 Yii 本身运行 dockerized 框架测试。
### 数据库管理工具
以 MySQL(`mysql`)的形式运行MySQL时,可以将 phpMyAdmin 容器添加到您的堆栈中,如下所示:
```
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- '8888:80'
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mysql
depends_on:
- mysql
```

211
docs/guide-zh-CN/tutorial-yii-as-micro-framework.md

@ -0,0 +1,211 @@
# 使用 Yii 作为微框架
Yii 可以轻松使用,而不需要基本和高级模板中包含的功能。换句话说,Yii 已经是一个微框架。不需要由模板提供的目录结构与 Yii 一起工作。
当你不需要像 assets 或视图一样的所有预定义模板代码时,这一点特别方便。 其中一种情况是构建 JSON API。 在下面的部分将展示如何做到这一点。
## 安装 Yii
为您的项目创建一个目录并将工作目录更改为该路径。示例中使用的命令是基于 Unix 的,但在 Windows 中也存在类似的命令。
```bash
mkdir micro-app
cd micro-app
```
> 注意:需要一些 Composer 的知识才能继续。如果您还不知道如何使用 composer,请花些时间阅读 [Composer 指南](https://getcomposer.org/doc/00-intro.md)。
使用您最喜爱的编辑器在 `micro-app` 目录下创建 `composer.json` 文件并添加以下内容:
```json
{
"require": {
"yiisoft/yii2": "~2.0.0"
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}
```
保存文件并运行 `composer install` 命令。这将安装框架及其所有依赖项。
## 创建项目结构
安装框架之后,需要为此应用程序创建一个 [入口点](structure-entry-scripts.md)。入口点是您尝试打开应用程序时将执行的第一个文件。 出于安全原因,建议将入口点文件放在一个单独的目录中,并将其设置为Web根目录。
创建一个 `web` 目录并将 `index.php` 放入其中,内容如下:
```php
<?php
// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require __DIR__ . '/../config.php';
(new yii\web\Application($config))->run();
```
还要创建一个名为 `config.php `的文件,它将包含所有的应用程序配置:
```php
<?php
return [
'id' => 'micro-app',
// the basePath of the application will be the `micro-app` directory
'basePath' => __DIR__,
// this is where the application will find all controllers
'controllerNamespace' => 'micro\controllers',
// set an alias to enable autoloading of classes from the 'micro' namespace
'aliases' => [
'@micro' => __DIR__,
],
];
```
> 信息:尽管配置可以保存在 `index.php` 文件中,建议单独使用它。
> 这样它也可以用于控制台应用程序,如下所示。
您的项目现在已经准备进行编码了。尽管由您决定项目目录结构,只要您遵守命名空间即可。
## 创建第一个控制器
创建一个 `controllers` 目录并添加一个文件 `SiteController.php`,这是默认的
控制器将处理没有路径信息的请求。
```php
<?php
namespace micro\controllers;
use yii\web\Controller;
class SiteController extends Controller
{
public function actionIndex()
{
return 'Hello World!';
}
}
```
如果您想为此控制器使用不同的名称,则可以配置 [[yii\base\Application::$defaultRoute]] 进行更改。
例如,对于 `DefaultController` 将会是 `'defaultRoute' => 'default/index'`
在这一点上,项目结构应该如下所示:
```
micro-app/
├── composer.json
├── config.php
├── web/
└── index.php
└── controllers/
└── SiteController.php
```
如果您尚未设置 Web 服务器,则可能需要查看[Web服务器配置文件示例](start-installation.md#configuring-web-servers)。
另一种选择是使用 `yii serve` 命令,它将使用 PHP 内置 web 服务器。
您可以通过以下方式从 `micro-app /` 目录运行它:
vendor/bin/yii serve --docroot=./web
在浏览器中打开应用程序URL现在应该打印出“Hello World!”,它已经在 `SiteController::actionIndex()` 中返回。
> 信息:在我们的示例中,我们已将默认应用程序名称空间 `app` 更改为 `micro`
> 以表明您不受此名称的限制(如果您是这样认为),
> 然后调整 [[yii\base\Application::$controllerNamespace|controllers namespace]] 并设置正确的别名。
## 创建一个 REST API
为了演示我们的“微框架”的用法,我们将为帖子创建一个简单的 REST API。
为了这个 API 来操作一些数据,我们首先需要一个数据库。 添加数据库连接配置
到应用程序配置:
```php
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'sqlite:@micro/database.sqlite',
],
],
```
> 信息:为了简单,我们在这里使用了一个 sqlite 数据库 请参阅[数据库指南](db-dao.md) 以获取更多选项。
接下来我们创建一个[数据库迁移](db-migrations.md)来创建一个帖子表。
确保你有一个单独的配置文件,如上所述,我们需要它来运行下面的控制台命令。
运行以下命令将创建数据库迁移文件
并将迁移应用到数据库:
vendor/bin/yii migrate/create --appconfig=config.php create_post_table --fields="title:string,body:text"
vendor/bin/yii migrate/up --appconfig=config.php
在该目录中创建目录 `models``Post.php` 文件。以下是模型的代码:
```php
<?php
namespace micro\models;
use yii\db\ActiveRecord;
class Post extends ActiveRecord
{
public static function tableName()
{
return '{{post}}';
}
}
```
> 信息:这里创建的模型是一个 ActiveRecord 类,它代表 `post` 表中的数据。
> 有关更多信息,请参阅[活动记录指南](db-active-record.md)。
我们要通过 API 发布帖子,请在 `controllers` 中添加 `PostController`
```php
<?php
namespace micro\controllers;
use yii\rest\ActiveController;
class PostController extends ActiveController
{
public $modelClass = 'micro\models\Post';
public function behaviors()
{
// remove rateLimiter which requires an authenticated user to work
$behaviors = parent::behaviors();
unset($behaviors['rateLimiter']);
return $behaviors;
}
}
```
此时我们的 API 将提供以下 URL :
- `/index.php?r=post` - 列出所有帖子
- `/index.php?r=post/view&id=1` - 显示 ID 为 1 的帖子
- `/index.php?r=post/create` - 创建一个帖子
- `/index.php?r=post/update&id=1` - 更新 ID 为 1 的帖子
- `/index.php?r=post/delete&id=1` - 删除 ID 为 1 的帖子
从这里开始,您可能需要查看以下指南以进一步开发您的应用程序:
- 该 API 目前仅将 urlencoded 表单数据理解为输入,若使其成为真正的 JSON API,
 您需要配置 [[yii\web\JsonParser]]。
- 为了使 URL 更加友好,您需要配置路由。
请参阅 [关于REST路由的指南](rest-routing.md) 了解如何执行此操作。
- 请参阅 [预览](start-looking-ahead.md) 部分获取更多参考。
Loading…
Cancel
Save