mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 22:30:27 +08:00
guide WIP [skip ci]
This commit is contained in:
@ -1,31 +1,56 @@
|
||||
Working with Databases
|
||||
======================
|
||||
|
||||
> Note: This section is under development.
|
||||
|
||||
In this section, we will describe how to create a new page to display data fetched from a database table.
|
||||
To achieve this goal, you will create an [action](structure-controllers.md), a [view](structure-views.md),
|
||||
and an [Active Record](db-active-record.md) model that can be used to fetch and represent database data.
|
||||
To achieve this goal, you will configure the database connection, create an [Active Record](db-active-record.md) class
|
||||
to fetch and represent database data, and then create an [action](structure-controllers.md) and
|
||||
a [view](structure-views.md) to present the data to end users.
|
||||
|
||||
Through this tutorial, you will learn
|
||||
|
||||
* How to configure database connections;
|
||||
* How to configure DB connections;
|
||||
* How to define an Active Record class;
|
||||
* How to query data using the Active Record class;
|
||||
* How to display data in a view in a paginated fashion.
|
||||
|
||||
Note that in order to finish this section, you should have basic knowledge and experience about databases.
|
||||
You should know how to create a database and how to execute SQL statements using a DB client tool.
|
||||
|
||||
|
||||
Configuring a Database Connection
|
||||
---------------------------------
|
||||
|
||||
To start, you should have a database ready. It can be a SQLite, MySQL, PostgreSQL, MSSQL or Oracle database.
|
||||
For simplicity, in the following description, we will assume that you already have a MySQL database named `basic`.
|
||||
|
||||
Create a table named `address` and insert some sample data. The SQL statements are showing as follows,
|
||||
|
||||
```sql
|
||||
CREATE TABLE `address` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`street` varchar(128),
|
||||
`city` varchar(128),
|
||||
`state` varchar(128),
|
||||
`country` varchar(128)
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
Creating an Active Record
|
||||
-------------------------
|
||||
|
||||
Creating a Model
|
||||
----------------
|
||||
|
||||
Creating an Action
|
||||
------------------
|
||||
|
||||
|
||||
Creating a View
|
||||
---------------
|
||||
|
||||
|
||||
How It Works
|
||||
------------
|
||||
|
||||
|
||||
Summary
|
||||
-------
|
||||
|
@ -1,8 +1,6 @@
|
||||
Working with Forms
|
||||
==================
|
||||
|
||||
> Note: This section is under development.
|
||||
|
||||
In this section, we will describe how to create a new page to get data from users.
|
||||
The page will display a form with a name input field and an email input field.
|
||||
After getting these data from a user, the page will echo them back to the user for confirmation.
|
||||
|
Reference in New Issue
Block a user