From ea9949c7298e1e8c7bede2f2c0ee9dded3013a1d Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 28 Jul 2013 11:49:46 -0400 Subject: [PATCH] minor doc update. --- build/build.bat | 44 ++++++++++++++++++++++---------------------- docs/guide/bootstrap.md | 2 +- docs/guide/index.md | 2 +- docs/guide/installation.md | 2 +- docs/guide/model.md | 28 +++++++++++++++++----------- docs/guide/mvc.md | 2 +- 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/build/build.bat b/build/build.bat index a1ae41f..e659199 100644 --- a/build/build.bat +++ b/build/build.bat @@ -1,23 +1,23 @@ -@echo off - -rem ------------------------------------------------------------- -rem build script for Windows. -rem -rem This is the bootstrap script for running build on Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright 2008 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem @version $Id$ -rem ------------------------------------------------------------- - -@setlocal - -set BUILD_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -%PHP_COMMAND% "%BUILD_PATH%build" %* - +@echo off + +rem ------------------------------------------------------------- +rem build script for Windows. +rem +rem This is the bootstrap script for running build on Windows. +rem +rem @author Qiang Xue +rem @link http://www.yiiframework.com/ +rem @copyright 2008 Yii Software LLC +rem @license http://www.yiiframework.com/license/ +rem @version $Id$ +rem ------------------------------------------------------------- + +@setlocal + +set BUILD_PATH=%~dp0 + +if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe + +%PHP_COMMAND% "%BUILD_PATH%build" %* + @endlocal \ No newline at end of file diff --git a/docs/guide/bootstrap.md b/docs/guide/bootstrap.md index c1a40b6..08dc6aa 100644 --- a/docs/guide/bootstrap.md +++ b/docs/guide/bootstrap.md @@ -4,7 +4,7 @@ Bootstrap with Yii Yii provides a few ready-to-use application templates. Based on your needs, you may choose one of them to bootstrap your project. -In following, we describe how to get started with the "Yii 2 Basic Application Template". +In the following, we describe how to get started with the "Yii 2 Basic Application Template". ### Install via Composer diff --git a/docs/guide/index.md b/docs/guide/index.md index 0c37a93..707b281 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -14,9 +14,9 @@ Base concepts ============= - [MVC Overview](mvc.md) -- [Controller](controller.md) - [Model](model.md) - [View](view.md) +- [Controller](controller.md) - [Application](application.md) Database diff --git a/docs/guide/installation.md b/docs/guide/installation.md index 3f9a803..1873d47 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -24,7 +24,7 @@ script via the following URL in a Web browser: http://hostname/path/to/yii/requirements/index.php ~~~ -Yii requires PHP 5.3, so the server must have PHP 5.3 or above installed and +Yii requires PHP 5.3.7, so the server must have PHP 5.3.7 or above installed and available to the web server. Yii has been tested with [Apache HTTP server](http://httpd.apache.org/) on Windows and Linux. It may also run on other Web servers and platforms, provided PHP 5.3 is supported. diff --git a/docs/guide/model.md b/docs/guide/model.md index b9d9812..bae9ab6 100644 --- a/docs/guide/model.md +++ b/docs/guide/model.md @@ -27,8 +27,8 @@ echo $post->title; echo $post->content; ``` -Since model implements [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php) interface you can use it -as if it was an array: +Since [[\yii\base\Model|Model]] implements the [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php) interface, +you can also access the attributes like accessing array elements: ```php $post = new Post; @@ -38,8 +38,9 @@ echo $post['title']; echo $post['content']; ``` -Default model implementation has a strict rule that all its attributes should be explicitly declared as public and -non-static class properties such as the following: +By default, [[\yii\base\Model|Model]] requires that attributes be declared as *public* and *non-static* +class member variables. In the following example, the `LoginForm` model class declares two attributes: +`username` and `password`. ```php // LoginForm has two attributes: username and password @@ -50,17 +51,22 @@ class LoginForm extends \yii\base\Model } ``` -In order to change this, you can override `attributes()` method that returns a list of model attribute names. +Derived model classes may use different ways to declare attributes by overriding the [[\yii\base\Model::attributes()|attributes()]] +method. For example, [[\yii\db\ActiveRecord]] defines attributes as the column names of the database table +that is associated with the class. -Attribute labels +Attribute Labels ---------------- Attribute labels are mainly used for display purpose. For example, given an attribute `firstName`, we can declare -a label `First Name` which is more user-friendly and can be displayed to end users for example as a form label. +a label `First Name` which is more user-friendly and can be displayed to end users in places such as form labels, +error messages. Given an attribute name, you can obtain its label by calling [[\yii\base\Model::getAttributeLabel()]]. -By default an attribute label is generated using [[\yii\base\Model\generateAttributeLabel()]] but the better way is to -specify it explicitly like the following: +To declare attribute labels, you should override the [[\yii\base\Model::attributeLabels()]] method and return +a mapping from attribute names to attribute labels, like shown in the example below. If an attribute is not found +in this mapping, its label will be generated using the [[\yii\base\Model::generateAttributeLabel()]] method, which +in many cases, will generate reasonable labels (e.g. `username` to `Username`, `orderNumber` to `Order Number`). ```php // LoginForm has two attributes: username and password @@ -71,7 +77,7 @@ class LoginForm extends \yii\base\Model public function attributeLabels() { - reuturn array( + return array( 'username' => 'Your name', 'password' => 'Your password', ); @@ -85,7 +91,7 @@ Scenarios A model may be used in different scenarios. For example, a `User` model may be used to collect user login inputs, and it may also be used for user registration purpose. For this reason, each model has a property named `scenario` which stores the name of the scenario that the model is currently being used in. As we will explain in the next -few sections, the concept of scenario is mainly used for validation and massive attribute assignment. +few sections, the concept of scenario is mainly used for data validation and massive attribute assignment. Associated with each scenario is a list of attributes that are *active* in that particular scenario. For example, in the `login` scenario, only the `username` and `password` attributes are active; while in the `register` scenario, diff --git a/docs/guide/mvc.md b/docs/guide/mvc.md index a99d043..f67ba4d 100644 --- a/docs/guide/mvc.md +++ b/docs/guide/mvc.md @@ -10,7 +10,7 @@ of the user interface such as text, form inputs; and the controller manages the communication between the model and the view. Besides implementing MVC, Yii also introduces a front-controller, called -`Application`, which encapsulates the execution context for the processing +`application`, which encapsulates the execution context for the processing of a request. Application collects information about a user request and then dispatches it to an appropriate controller for further handling.