mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-08 00:47:55 +08:00
Merge pull request #7822 from bitsofmymind/documentation-fixes
[skip ci] Fixed markup, text mistakes and inconsistencies in the documentation
This commit is contained in:
@ -212,7 +212,7 @@ $customer = Customer::findAll([
|
||||
to improve the performance, e.g., `Customer::find()->limit(1)->one()`.
|
||||
|
||||
Besides using query building methods, you can also write raw SQLs to query data and populate the results into
|
||||
Active Record objects. You can do so by calling the [[yii\db\ActiveRecord::queryBySql()]] method:
|
||||
Active Record objects. You can do so by calling the [[yii\db\ActiveRecord::findBySql()]] method:
|
||||
|
||||
```php
|
||||
// returns all inactive customers
|
||||
@ -220,7 +220,7 @@ $sql = 'SELECT * FROM customer WHERE status=:status';
|
||||
$customers = Customer::findBySql($sql, [':status' => Customer::STATUS_INACTIVE])->all();
|
||||
```
|
||||
|
||||
Do not call extra query building methods after calling [[yii\db\ActiveRecord::queryBySql()|queryBySql()]] as they
|
||||
Do not call extra query building methods after calling [[yii\db\ActiveRecord::findBySql()|findBySql()]] as they
|
||||
will be ignored.
|
||||
|
||||
|
||||
@ -1010,7 +1010,7 @@ $customers = Customer::find()
|
||||
> Note: It is important to disambiguate column names when building relational queries involving JOIN SQL statements.
|
||||
A common practice is to prefix column names with their corresponding table names.
|
||||
|
||||
However, a better approaches is to exploit the existing relation declarations by calling [[yii\db\ActiveQuery::joinWith()]]:
|
||||
However, a better approach is to exploit the existing relation declarations by calling [[yii\db\ActiveQuery::joinWith()]]:
|
||||
|
||||
```php
|
||||
$customers = Customer::find()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
ArrayHelper
|
||||
===========
|
||||
|
||||
Additionally to [rich set of PHP array functions](http://php.net/manual/en/book.array.php) Yii array helper provides
|
||||
Additionally to the [rich set of PHP array functions](http://php.net/manual/en/book.array.php), the Yii array helper provides
|
||||
extra static methods allowing you to deal with arrays more efficiently.
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ Url helper provides a set of static methods for managing URLs.
|
||||
## Getting Common URLs <span id="getting-common-urls"></span>
|
||||
|
||||
There are two methods you can use to get common URLs: home URL and base URL of the current request. In order to get
|
||||
home URL use the following:
|
||||
home URL, use the following:
|
||||
|
||||
```php
|
||||
$relativeHomeUrl = Url::home();
|
||||
@ -15,10 +15,10 @@ $absoluteHomeUrl = Url::home(true);
|
||||
$httpsAbsoluteHomeUrl = Url::home('https');
|
||||
```
|
||||
|
||||
If no parameter is passed, URL generated is relative. You can either pass `true` to get absolute URL for the current
|
||||
schema or specify schema explicitly (`https`, `http`).
|
||||
If no parameter is passed, the generated URL is relative. You can either pass `true` to get an absolute URL for the current
|
||||
schema or specify a schema explicitly (`https`, `http`).
|
||||
|
||||
To get base URL of the current request use the following:
|
||||
To get the base URL of the current request use the following:
|
||||
|
||||
```php
|
||||
$relativeBaseUrl = Url::base();
|
||||
@ -31,7 +31,7 @@ The only parameter of the method works exactly the same as for `Url::home()`.
|
||||
|
||||
## Creating URLs <span id="creating-urls"></span>
|
||||
|
||||
In order to create URL to a given route use `Url::toRoute()` method. The method uses [[\yii\web\UrlManager]] to create
|
||||
In order to create a URL to a given route use the `Url::toRoute()` method. The method uses [[\yii\web\UrlManager]] to create
|
||||
a URL:
|
||||
|
||||
```php
|
||||
@ -53,7 +53,7 @@ If you want to create a URL with an anchor, you can use the array format with a
|
||||
['site/index', 'param1' => 'value1', '#' => 'name']
|
||||
```
|
||||
|
||||
A route may be either absolute or relative. An absolute route has a leading slash (e.g. `/site/index`), while a relative
|
||||
A route may be either absolute or relative. An absolute route has a leading slash (e.g. `/site/index`) while a relative
|
||||
route has none (e.g. `site/index` or `index`). A relative route will be converted into an absolute one by the following rules:
|
||||
|
||||
- If the route is an empty string, the current [[\yii\web\Controller::route|route]] will be used;
|
||||
|
||||
@ -74,7 +74,7 @@ To customize the output, you can chain additional methods of [[yii\widgets\Activ
|
||||
```
|
||||
|
||||
This will create all the `<label>`, `<input>` and other tags according to the [[yii\widgets\ActiveField::$template|template]] defined by the form field.
|
||||
The name of the input field is determined automatically from the model's [[yii\base\Model::formName()|form name] and the attribute's name.
|
||||
The name of the input field is determined automatically from the model's [[yii\base\Model::formName()|form name]] and the attribute's name.
|
||||
For example, the name for the input field for the `username` attribute in the above example will be `LoginForm[username]`. This naming rule will result in an array
|
||||
of all attributes for the login form to be available in `$_POST['LoginForm']` on the server side.
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ application views, the following should be in your application config file:
|
||||
In the above, `pathMap` defines a map of original paths to themed paths while `baseUrl` defines the base URL for
|
||||
resources referenced by theme files.
|
||||
|
||||
In our case `pathMap` is `['@app/views' => '@app/themes/basic']`. That means that every view in `@app/views` will be
|
||||
In our case, `pathMap` is `['@app/views' => '@app/themes/basic']`. That means that every view in `@app/views` will be
|
||||
first searched under `@app/themes/basic` and if a view exists in the theme directory it will be used instead of the
|
||||
original view.
|
||||
|
||||
@ -38,8 +38,8 @@ For example, with a configuration above a themed version of a view file `@app/vi
|
||||
`@app/themes/basic/site/index.php`. It basically replaces `@app/views` in `@app/views/site/index.php` with
|
||||
`@app/themes/basic`.
|
||||
|
||||
In order to configure theme runtime you can use the following code before rendering a view. Typically it will be
|
||||
placed in controller:
|
||||
In order to configure a theme at runtime, you can use the following code before rendering a view. Typically, it will be
|
||||
placed in a controller:
|
||||
|
||||
```php
|
||||
$this->getView()->theme = Yii::createObject([
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
Security
|
||||
Working with Passwords
|
||||
========
|
||||
|
||||
> Note: This section is under development.
|
||||
@ -6,7 +6,7 @@ Security
|
||||
Good security is vital to the health and success of any application. Unfortunately, many developers cut corners when it comes to security, either due to a lack of understanding or because implementation is too much of a hurdle. To make your Yii powered application as secure as possible, Yii has included several excellent and easy to use security features.
|
||||
|
||||
|
||||
Hashing and verifying passwords
|
||||
Hashing and Verifying Passwords
|
||||
-------------------------------
|
||||
|
||||
Most developers know that passwords cannot be stored in plain text, but many developers believe it's still safe to hash passwords using `md5` or `sha1`. There was a time when using the aforementioned hashing algorithms was sufficient, but modern hardware makes it possible to reverse such hashes very quickly using brute force attacks.
|
||||
@ -33,7 +33,7 @@ if (Yii::$app->getSecurity()->validatePassword($password, $hash)) {
|
||||
}
|
||||
```
|
||||
|
||||
Generating Pseudorandom data
|
||||
Generating Pseudorandom Data
|
||||
-----------
|
||||
|
||||
Pseudorandom data is useful in many situations. For example when resetting a password via email you need to generate a token, save it to the database, and send it via email to end user which in turn will allow them to prove ownership of that account. It is very important that this token be unique and hard to guess, else there is a possibility that attacker can predict the token's value and reset the user's password.
|
||||
@ -47,7 +47,7 @@ $key = Yii::$app->getSecurity()->generateRandomString();
|
||||
|
||||
Note that you need to have the `openssl` extension installed in order to generate cryptographically secure random data.
|
||||
|
||||
Encryption and decryption
|
||||
Encryption and Decryption
|
||||
-------------------------
|
||||
|
||||
Yii provides convenient helper functions that allow you to encrypt/decrypt data using a secret key. The data is passed through the encryption function so that only the person which has the secret key will be able to decrypt it.
|
||||
@ -67,7 +67,7 @@ Subsequently when user wants to read the data:
|
||||
$data = Yii::$app->getSecurity()->decryptByPassword($encryptedData, $secretKey);
|
||||
```
|
||||
|
||||
Confirming data integrity
|
||||
Confirming Data Integrity
|
||||
--------------------------------
|
||||
|
||||
There are situations in which you need to verify that your data hasn't been tampered with by a third party or even corrupted in some way. Yii provides an easy way to confirm data integrity in the form of two helper functions.
|
||||
|
||||
Reference in New Issue
Block a user