Commit 595faca9 by Qiang Xue

Finished the quick start guide. [skip ci]

parent b80c0c3b
......@@ -89,6 +89,8 @@ To represent and fetch the data in the `country` table, create an [Active Record
class named `Country` and save it in the file `models/Country.php`.
```php
<?php
namespace app\models;
use yii\db\ActiveRecord;
......@@ -136,6 +138,8 @@ for all actions about manipulating country data. Name this new controller as `Co
an `index` action in it, as shown in the following,
```php
<?php
namespace app\controllers;
use yii\web\Controller;
......@@ -193,6 +197,7 @@ with the following content:
use yii\helpers\Html;
use yii\widgets\LinkPager;
?>
<h1>Countries</h1>
<ul>
<?php foreach ($countries as $country): ?>
<li>
......@@ -220,6 +225,8 @@ To see how it works, use your browser to access the following URL:
http://hostname/index.php?r=country/index
```
![Country List](images/start-country-list.png)
You will see a page showing five countries. And below the countries, you will see a pager with four buttons.
If you click on the button "2", you will see that the page displays another five countries in the database.
Observe more carefully and you will find the URL in the browser changes to
......
......@@ -23,6 +23,8 @@ save the class in the file `models/EntryForm.php`. Please refer to the [Class Au
section for more details about the class file naming convention.
```php
<?php
namespace app\models;
use yii\base\Model;
......@@ -64,6 +66,8 @@ Creating an Action <a name="creating-action"></a>
Next, create an `entry` action in the `site` controller, like you did in the previous section.
```php
<?php
namespace app\controllers;
use Yii;
......@@ -170,9 +174,14 @@ is also displayed indicating what data you need to enter. If you click the submi
entering anything, or if you do not provide a valid email address, you will see an error message that
is displayed next to each problematic input field.
![Form with Validation Errors](images/start-form-validation.png)
After entering a valid name and email address and clicking the submit button, you will see a new page
displaying the data that you just entered.
![Confirmation of Data Entry](images/start-entry-confirmation.png)
### Magic Explained <a name="magic-explained"></a>
......
......@@ -45,26 +45,28 @@ Therefore, your application has already enabled Gii, and you can access it via t
http://hostname/index.php?r=gii
```
![Gii](images/start-gii.png)
Generating an Active Record Class <a name="generating-ar"></a>
---------------------------------
To use Gii to generate an Active Record class, select the "Model Generator". You will see the following page:
Fill out the form as follows:
To use Gii to generate an Active Record class, select the "Model Generator" and fill out the form as follows,
* Table Name: `country`
* Model Class: `Country`
![Model Generator](images/start-gii-model.png)
Click on the "Preview" button. You will see `models/Country.php` is listed in the result.
You may click on it to preview its content.
Because in the last section, you have already created the same file `models/Country.php`, if you click
the `diff` button next to the file name, you will see the difference between the code to be generated
and the code that you have already written.
![Model Generator Preview](images/start-gii-model-preview.png)
Check the checkbox next to "overwrite" and then click on the "Generate" button. You will see
a confirmation page indicating the code has been successfully generated and your existing `models/Country.php`
is overwritten with the newly generated code.
......@@ -79,12 +81,13 @@ To create CRUD code, select the "CRUD Generator". Fill out the form as follows:
* Search Model Class: `app\models\CountrySearch`
* Controller Class: `app\controllers\CountryController`
Click on the "Preview" button. You will see a list of files to be generated, as shown below.
![CRUD Generator](images/start-gii-crud.png)
Click on the "Preview" button. You will see a list of files to be generated, as shown below.
Make sure you have checked the checkbox for the `controllers/CityController.php` line. This is needed
because you have already created this file in the previous section and the file needs to be overwritten
to have full CRUD support.
Make sure you have checked the overwrite checkboxes for both `controllers/CountryController.php` and
`views/country/index.php` files. This is needed because you have already created these files
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>
......@@ -102,6 +105,10 @@ or filter it by entering filter conditions in the column headers.
For each country displayed in the grid, you may choose to view its detail, update it or delete it.
You may also click on the "Create Country" button on top of the grid to create a new country.
![Data Grid of Countries](images/start-gii-country-grid.png)
![Updating a Country](images/start-gii-country-update.png)
The following is the list of the generated files in case you want to dig out how these features are implemented,
or if you want to customize them.
......
......@@ -31,6 +31,8 @@ declare the `say` action in the existing controller `SiteController` which is de
in the class file `controllers/SiteController.php`:
```php
<?php
namespace app\controllers;
use yii\web\Controller;
......@@ -100,6 +102,8 @@ After creating the action and the view, you may access the new page by the follo
http://hostname/index.php?r=site/say&message=Hello+World
```
![Hello World](images/start-hello-world.png)
This will show a page displaying "Hello World". The page shares the same header and footer as other pages of
the application. If you omit the `message` parameter in the URL, you would see the page displays "Hello".
This is because `message` is passed as a parameter to the `actionSay()` method, and when it is omitted,
......
......@@ -73,7 +73,9 @@ and the server name is `hostname`,
http://hostname/basic/web/index.php
```
You should see a "Congratulations!" page in your browser. If not, please check if your PHP installation satisfies
![Successful Installation of Yii](images/start-app-installed.png)
You should see the above "Congratulations!" page in your browser. If not, please check if your PHP installation satisfies
Yii's requirements by using one of the following approaches:
* Use a browser to access the URL `http://hostname/basic/requirements.php`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment