Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
3c9a0aca
Commit
3c9a0aca
authored
May 13, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
guide WIP [skip ci]
parent
3cf5ffe4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
20 deletions
+29
-20
README.md
docs/guide/README.md
+1
-1
rest-quick-start.md
docs/guide/rest-quick-start.md
+17
-8
start-databases.md
docs/guide/start-databases.md
+2
-2
start-forms.md
docs/guide/start-forms.md
+2
-2
start-gii.md
docs/guide/start-gii.md
+2
-2
start-hello.md
docs/guide/start-hello.md
+2
-2
start-workflow.md
docs/guide/start-workflow.md
+3
-3
No files found.
docs/guide/README.md
View file @
3c9a0aca
...
@@ -121,7 +121,7 @@ Caching
...
@@ -121,7 +121,7 @@ Caching
RESTful Web Services
RESTful Web Services
--------------------
--------------------
*
[
Quick Start
](
rest-quick-start.md
)
*
[
A
Quick Start
](
rest-quick-start.md
)
*
[
Resources
](
rest-resources.md
)
*
[
Resources
](
rest-resources.md
)
*
[
Controllers
](
rest-controllers.md
)
*
[
Controllers
](
rest-controllers.md
)
*
[
Routing
](
rest-routing.md
)
*
[
Routing
](
rest-routing.md
)
...
...
docs/guide/rest-quick-start.md
View file @
3c9a0aca
Quick Start
A
Quick Start
===========
===========
==
Yii provides a whole set of tools to simplify the task of implementing RESTful Web Service APIs.
Yii provides a whole set of tools to simplify the task of implementing RESTful Web Service APIs.
In particular, Yii
provides support for the following aspects regarding
RESTful APIs:
In particular, Yii
supports the following features about
RESTful APIs:
*
Quick prototyping with support for common APIs for
[
Active Record
](
db-active-record.md
)
;
*
Quick prototyping with support for common APIs for
[
Active Record
](
db-active-record.md
)
;
*
Response format (supporting JSON and XML by default) negotiation;
*
Response format (supporting JSON and XML by default) negotiation;
...
@@ -16,7 +16,8 @@ In particular, Yii provides support for the following aspects regarding RESTful
...
@@ -16,7 +16,8 @@ In particular, Yii provides support for the following aspects regarding RESTful
*
Rate limiting;
*
Rate limiting;
Let's use a quick example to show how to build a set of RESTful APIs using Yii.
In the following, we use an example to illustrate how you can build a set of RESTful APIs with some minimal coding effort.
Assume you want to expose the user data via RESTful APIs. The user data are stored in the user DB table,
Assume you want to expose the user data via RESTful APIs. The user data are stored in the user DB table,
and you have already created the
[
[yii\db\ActiveRecord|ActiveRecord
]
] class
`app\models\User`
to access the user data.
and you have already created the
[
[yii\db\ActiveRecord|ActiveRecord
]
] class
`app\models\User`
to access the user data.
...
@@ -37,6 +38,9 @@ class UserController extends ActiveController
...
@@ -37,6 +38,9 @@ class UserController extends ActiveController
}
}
```
```
The controller class extends from
[
[yii\rest\ActiveController
]
]. By specifying
[
[yii\rest\ActiveController::modelClass|modelClass
]
]
as
`app\models\User`
, the controller knows what model can be used for fetching and manipulating data.
Configuring URL Rules
Configuring URL Rules
---------------------
---------------------
...
@@ -54,7 +58,11 @@ Then, modify the configuration about the `urlManager` component in your applicat
...
@@ -54,7 +58,11 @@ Then, modify the configuration about the `urlManager` component in your applicat
]
]
```
```
Trying it Out
The above configuration mainly adds a URL rule for the
`user`
controller so that the user data
can be accessed and manipulated with pretty URLs and meaningful HTTP verbs.
Trying it Out <a name="trying-it-out"></a>
-------------
-------------
With the above minimal amount of effort, you have already finished your task of creating the RESTful APIs
With the above minimal amount of effort, you have already finished your task of creating the RESTful APIs
...
@@ -159,10 +167,11 @@ Using the Yii RESTful API framework, you implement an API endpoint in terms of a
...
@@ -159,10 +167,11 @@ Using the Yii RESTful API framework, you implement an API endpoint in terms of a
a controller to organize the actions that implement the endpoints for a single type of resource.
a controller to organize the actions that implement the endpoints for a single type of resource.
Resources are represented as data models which extend from the
[
[yii\base\Model
]
] class.
Resources are represented as data models which extend from the
[
[yii\base\Model
]
] class.
If you are working with databases (relational or NoSQL), it is recommended you use ActiveRecord to represent resources.
If you are working with databases (relational or NoSQL), it is recommended you use
[
[yii\db\ActiveRecord|ActiveRecord
]
]
to represent resources.
You may use
[
[yii\rest\UrlRule
]
] to simplify the routing to your API endpoints.
You may use
[
[yii\rest\UrlRule
]
] to simplify the routing to your API endpoints.
While not required, it is recommended that you develop your RESTful APIs as a
n application, separated
from
While not required, it is recommended that you develop your RESTful APIs as a
separate application, different
from
your Web front end and back end.
your Web front end and back end
for easier maintenance
.
docs/guide/start-databases.md
View file @
3c9a0aca
...
@@ -216,8 +216,8 @@ The `LinkPager` widget displays a list of page buttons. Clicking on any of them
...
@@ -216,8 +216,8 @@ The `LinkPager` widget displays a list of page buttons. Clicking on any of them
in the corresponding page.
in the corresponding page.
How It Works <a name="how-it-works
"></a>
Trying it Out <a name="trying-it-out
"></a>
------------
------------
-
To see how it works, use your browser to access the following URL:
To see how it works, use your browser to access the following URL:
...
...
docs/guide/start-forms.md
View file @
3c9a0aca
...
@@ -160,8 +160,8 @@ and the second the "email" data. After the input fields, the [[yii\helpers\Html:
...
@@ -160,8 +160,8 @@ and the second the "email" data. After the input fields, the [[yii\helpers\Html:
is called to generate a submit button.
is called to generate a submit button.
How It Works <a name="how-it-works
"></a>
Trying it Out <a name="trying-it-out
"></a>
------------
------------
-
To see how it works, use your browser to access the following URL:
To see how it works, use your browser to access the following URL:
...
...
docs/guide/start-gii.md
View file @
3c9a0aca
...
@@ -90,8 +90,8 @@ Make sure you have checked the overwrite checkboxes for both `controllers/Countr
...
@@ -90,8 +90,8 @@ Make sure you have checked the overwrite checkboxes for both `controllers/Countr
in the previous section and you want to have them overwritten to have full CRUD support.
in the previous section and you want to have them overwritten to have full CRUD support.
How It Works <a name="how-it-works
"></a>
Trying it Out <a name="trying-it-out
"></a>
------------
------------
-
To see how it works, use your browser to access the following URL:
To see how it works, use your browser to access the following URL:
...
...
docs/guide/start-hello.md
View file @
3c9a0aca
...
@@ -93,8 +93,8 @@ In fact, the `say` view is just a PHP script which is executed by the [[yii\web\
...
@@ -93,8 +93,8 @@ In fact, the `say` view is just a PHP script which is executed by the [[yii\web\
The content echoed by the view script will be forwarded by the application as the response to the end user.
The content echoed by the view script will be forwarded by the application as the response to the end user.
How It Works <a name="how-it-works
"></a>
Trying it Out <a name="trying-it-out
"></a>
------------
------------
-
After creating the action and the view, you may access the new page by the following URL:
After creating the action and the view, you may access the new page by the following URL:
...
...
docs/guide/start-workflow.md
View file @
3c9a0aca
...
@@ -11,7 +11,7 @@ and how the application handles requests in general.
...
@@ -11,7 +11,7 @@ and how the application handles requests in general.
Please adjust the URLs accordingly in our descriptions.
Please adjust the URLs accordingly in our descriptions.
Functionalities
Functionalities
<a name="functionalities"></a>
---------------
---------------
The application that you have installed contains four pages:
The application that you have installed contains four pages:
...
@@ -30,7 +30,7 @@ This is a useful [debugger tool](tool-debugger.md) provided by Yii to help you c
...
@@ -30,7 +30,7 @@ This is a useful [debugger tool](tool-debugger.md) provided by Yii to help you c
about the application execution, such as log messages, response status, database queries, and so on.
about the application execution, such as log messages, response status, database queries, and so on.
Application Structure
Application Structure
<a name="application-structure"></a>
---------------------
---------------------
The following is a list of the most important directories and files in your application,
The following is a list of the most important directories and files in your application,
...
@@ -72,7 +72,7 @@ and dispatches the request to MVC. [Widgets](structure-widgets.md) are used in t
...
@@ -72,7 +72,7 @@ and dispatches the request to MVC. [Widgets](structure-widgets.md) are used in t
to help build complex and dynamic user interface elements.
to help build complex and dynamic user interface elements.
Request Lifecycle
Request Lifecycle
<a name="request-lifecycle"></a>
-----------------
-----------------
The following diagram shows how an application handles a request.
The following diagram shows how an application handles a request.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment