Commit dfd68954 by Carsten Brandt

finished guide on formatting

parent 5617f295
...@@ -29,7 +29,8 @@ if ($data === false) { ...@@ -29,7 +29,8 @@ if ($data === false) {
Data caching relies on the so-called *cache components* which represent various cache storage, Data caching relies on the so-called *cache components* which represent various cache storage,
such as memory, files, databases. such as memory, files, databases.
Cache components are usually registered as application components so that they can be globally configurable Cache components are usually registered as [application components](structure-application-components.md) so
that they can be globally configurable
and accessible. The following code shows how to configure the `cache` application component to use and accessible. The following code shows how to configure the `cache` application component to use
[memcached](http://memcached.org/) with two cache servers: [memcached](http://memcached.org/) with two cache servers:
......
...@@ -97,7 +97,7 @@ Connecting to Database ...@@ -97,7 +97,7 @@ Connecting to Database
---------------------- ----------------------
Active Record uses a [[yii\db\Connection|DB connection]] to exchange data with database. By default, Active Record uses a [[yii\db\Connection|DB connection]] to exchange data with database. By default,
it uses the `db` application component as the connection. As explained in [Database basics](db-dao.md), it uses the `db` [application component](structure-application-components.md) as the connection. As explained in [Database basics](db-dao.md),
you may configure the `db` component in the application configuration file like follows, you may configure the `db` component in the application configuration file like follows,
```php ```php
......
...@@ -76,7 +76,7 @@ $primaryConnection = \Yii::$app->db; ...@@ -76,7 +76,7 @@ $primaryConnection = \Yii::$app->db;
$secondaryConnection = \Yii::$app->secondDb; $secondaryConnection = \Yii::$app->secondDb;
``` ```
If you don't want to define the connection as an application component you can instantiate it directly: If you don't want to define the connection as an [application component](structure-application-components.md) you can instantiate it directly:
```php ```php
$connection = new \yii\db\Connection([ $connection = new \yii\db\Connection([
......
...@@ -178,7 +178,7 @@ After applying a migration, the migration tool will keep a record in a database ...@@ -178,7 +178,7 @@ After applying a migration, the migration tool will keep a record in a database
table named `migration`. This allows the tool to identify which migrations table named `migration`. This allows the tool to identify which migrations
have been applied and which are not. If the `migration` table does not exist, have been applied and which are not. If the `migration` table does not exist,
the tool will automatically create it in the database specified by the `db` the tool will automatically create it in the database specified by the `db`
application component. [application component](structure-application-components.md).
Sometimes, we may only want to apply one or a few new migrations. We can use the Sometimes, we may only want to apply one or a few new migrations. We can use the
following command: following command:
...@@ -293,7 +293,7 @@ line: ...@@ -293,7 +293,7 @@ line:
migration history information. It defaults to `migration`. The table migration history information. It defaults to `migration`. The table
structure is `version varchar(255) primary key, apply_time integer`. structure is `version varchar(255) primary key, apply_time integer`.
* `db`: string, specifies the ID of the database application component. * `db`: string, specifies the ID of the database [application component](structure-application-components.md).
Defaults to 'db'. Defaults to 'db'.
* `templateFile`: string, specifies the path of the file to be served as the code * `templateFile`: string, specifies the path of the file to be served as the code
...@@ -341,7 +341,7 @@ can be also configured this way. ...@@ -341,7 +341,7 @@ can be also configured this way.
### Migrating with Multiple Databases ### Migrating with Multiple Databases
By default, migrations will be applied to the database specified by the `db` application component. By default, migrations will be applied to the database specified by the `db` [application component](structure-application-components.md).
You may change it by specifying the `--db` option, for example, You may change it by specifying the `--db` option, for example,
``` ```
......
...@@ -135,13 +135,13 @@ You may specify various container HTML options passing arrays to: ...@@ -135,13 +135,13 @@ You may specify various container HTML options passing arrays to:
- `footerOptions` - `footerOptions`
- `filterOptions` - `filterOptions`
#### Data column #### Data column <a name="data-column"></a>
Data column is for displaying and sorting data. It is default column type so specifying class could be omitted when Data column is for displaying and sorting data. It is default column type so specifying class could be omitted when
using it. using it.
The main setting of the data column is its format. It could be specified via `format` attribute. Its values are The main setting of the data column is its format. It could be specified via `format` attribute. Its values are
corresponding to methods in `format` application component that is [[\yii\i18n\Formatter|Formatter]] by default: corresponding to methods in `formatter` [application component](structure-application-components.md) that is [[\yii\i18n\Formatter|Formatter]] by default:
```php ```php
<?= GridView::widget([ <?= GridView::widget([
......
...@@ -16,7 +16,7 @@ The [[yii\web\ErrorHandler|error handler]] is enabled by default. You may disabl ...@@ -16,7 +16,7 @@ The [[yii\web\ErrorHandler|error handler]] is enabled by default. You may disabl
## Using Error Handler <a name="using-error-handler"></a> ## Using Error Handler <a name="using-error-handler"></a>
The [[yii\web\ErrorHandler|error handler]] is registered as an application component named `errorHandler`. The [[yii\web\ErrorHandler|error handler]] is registered as an [application component](structure-application-components.md) named `errorHandler`.
You may configure it in the application configuration like the following: You may configure it in the application configuration like the following:
```php ```php
......
...@@ -63,7 +63,7 @@ severity levels and categories and then exports them to some medium. For example ...@@ -63,7 +63,7 @@ severity levels and categories and then exports them to some medium. For example
exports the filtered log messages to a database table, while a [[yii\log\EmailTarget|email target]] exports exports the filtered log messages to a database table, while a [[yii\log\EmailTarget|email target]] exports
the log messages to specified email addresses. the log messages to specified email addresses.
You can register multiple log targets in an application by configuring them through the `log` application component You can register multiple log targets in an application by configuring them through the `log` [application component](structure-application-components.md)
in the application configuration, like the following: in the application configuration, like the following:
```php ```php
......
...@@ -154,7 +154,7 @@ the [Wiki article](http://en.wikipedia.org/wiki/Role-based_access_control) for d ...@@ -154,7 +154,7 @@ the [Wiki article](http://en.wikipedia.org/wiki/Role-based_access_control) for d
with other more traditional access control schemes. with other more traditional access control schemes.
Yii implements a General Hierarchical RBAC, following the [NIST RBAC model](http://csrc.nist.gov/rbac/sandhu-ferraiolo-kuhn-00.pdf). Yii implements a General Hierarchical RBAC, following the [NIST RBAC model](http://csrc.nist.gov/rbac/sandhu-ferraiolo-kuhn-00.pdf).
It provides the RBAC functionality through the [[yii\rbac\ManagerInterface|authManager]] application component. It provides the RBAC functionality through the [[yii\rbac\ManagerInterface|authManager]] [application component](structure-application-components.md).
Using RBAC involves two parts of work. The first part is to build up the RBAC authorization data, and the second Using RBAC involves two parts of work. The first part is to build up the RBAC authorization data, and the second
part is to use the authorization data to perform access check in places where it is needed. part is to use the authorization data to perform access check in places where it is needed.
......
...@@ -195,7 +195,7 @@ The rest of the array elements (key-value pairs) specify the parameters to be bo ...@@ -195,7 +195,7 @@ The rest of the array elements (key-value pairs) specify the parameters to be bo
#### [[yii\base\Application::components|components]] <a name="components"></a> #### [[yii\base\Application::components|components]] <a name="components"></a>
This is the single most important property. It allows you to register a list of named components This is the single most important property. It allows you to register a list of named components
called [application components](#structure-application-components.md) that you can use in other places. For example, called [application components](structure-application-components.md) that you can use in other places. For example,
```php ```php
[ [
......
...@@ -4,7 +4,7 @@ Views ...@@ -4,7 +4,7 @@ Views
Views are part of the [MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) architecture. Views are part of the [MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) architecture.
They are code responsible for presenting data to end users. In a Web application, views are usually created They are code responsible for presenting data to end users. In a Web application, views are usually created
in terms of *view templates* which are PHP script files containing mainly HTML code and presentational PHP code. in terms of *view templates* which are PHP script files containing mainly HTML code and presentational PHP code.
They are managed by the [[yii\web\View|view]] application component which provides commonly used methods They are managed by the [[yii\web\View|view]] [application component](structure-application-components.md) which provides commonly used methods
to facilitate view composition and rendering. For simplicity, we often call view templates or view template files to facilitate view composition and rendering. For simplicity, we often call view templates or view template files
as views. as views.
......
...@@ -63,7 +63,7 @@ Configuration ...@@ -63,7 +63,7 @@ Configuration
------------- -------------
As can be seen in the code above, the console application uses its own configuration file, named `console.php`. In this file As can be seen in the code above, the console application uses its own configuration file, named `console.php`. In this file
you should configure various application components and properties for the console application in particular. you should configure various [application components](structure-application-components.md) and properties for the console application in particular.
If your web application and the console application share a lot of configuration parameters and values, you may consider moving the common If your web application and the console application share a lot of configuration parameters and values, you may consider moving the common
parts into a separate file, and including this file in both of the application configurations (web and console). You can see an example of this in the "advanced" application template. parts into a separate file, and including this file in both of the application configurations (web and console). You can see an example of this in the "advanced" application template.
......
...@@ -71,7 +71,7 @@ echo \Yii::t('app', 'This is a string to translate!'); ...@@ -71,7 +71,7 @@ echo \Yii::t('app', 'This is a string to translate!');
``` ```
Yii tries to load an appropriate translation according to the current [[yii\base\Application::$language|application language]] Yii tries to load an appropriate translation according to the current [[yii\base\Application::$language|application language]]
from one of the message sources defined in the `i18n` [application component](concept-components.md). from one of the message sources defined in the `i18n` [application component](structure-application-components.md).
A message source is a set of files or a database that provides translation messages. A message source is a set of files or a database that provides translation messages.
The following configuration example defines a messages source that takes the messages from PHP files: The following configuration example defines a messages source that takes the messages from PHP files:
...@@ -408,7 +408,7 @@ Instead of using `fileMap` you can simply use convention of category mapping to ...@@ -408,7 +408,7 @@ Instead of using `fileMap` you can simply use convention of category mapping to
Yii comes with default translation messages for validation errors and some other strings. These messages are all Yii comes with default translation messages for validation errors and some other strings. These messages are all
in the category `yii`. Sometimes you want to correct default framework message translation for your application. in the category `yii`. Sometimes you want to correct default framework message translation for your application.
In order to do so configure the `i18n` [application component](concept-components.md) like the following: In order to do so configure the `i18n` [application component](structure-application-components.md) like the following:
```php ```php
'i18n' => [ 'i18n' => [
......
...@@ -78,7 +78,7 @@ return [ ...@@ -78,7 +78,7 @@ return [
]; ];
``` ```
Note that `cache` application component should be configured. Note that the `cache` [application component](structure-application-components.md) should be configured.
### Combining and Minimizing Assets ### Combining and Minimizing Assets
......
...@@ -106,7 +106,7 @@ which is not needed in this case and already handled by the existing application ...@@ -106,7 +106,7 @@ which is not needed in this case and already handled by the existing application
Like in a Yii application, you should configure the application instance based on the environment running Like in a Yii application, you should configure the application instance based on the environment running
the third-party system. For example, to use the [Active Record](db-active-record.md) feature, you need to configure the third-party system. For example, to use the [Active Record](db-active-record.md) feature, you need to configure
the `db` application component with the DB connection setting used by the third-party system. the `db` [application component](structure-application-components.md) with the DB connection setting used by the third-party system.
Now you can use most features provided by Yii. For example, you can create Active Record classes and use them Now you can use most features provided by Yii. For example, you can create Active Record classes and use them
to work with databases. to work with databases.
......
...@@ -57,7 +57,7 @@ Using the .less files of Bootstrap directly ...@@ -57,7 +57,7 @@ Using the .less files of Bootstrap directly
If you want to include the [Bootstrap css directly in your less files](http://getbootstrap.com/getting-started/#customizing) If you want to include the [Bootstrap css directly in your less files](http://getbootstrap.com/getting-started/#customizing)
you may need to disable the original bootstrap css files to be loaded. you may need to disable the original bootstrap css files to be loaded.
You can do this by setting the css property of the [[yii\bootstrap\BootstrapAsset|BootstrapAsset]] to be empty. You can do this by setting the css property of the [[yii\bootstrap\BootstrapAsset|BootstrapAsset]] to be empty.
For this you need to configure the `assetManager` application component as follows: For this you need to configure the `assetManager` [application component](structure-application-components.md) as follows:
```php ```php
'assetManager' => [ 'assetManager' => [
......
...@@ -258,6 +258,7 @@ class Formatter extends Component ...@@ -258,6 +258,7 @@ class Formatter extends Component
/** /**
* Formats the value as is without any formatting. * Formats the value as is without any formatting.
* This method simply returns back the parameter without any format. * This method simply returns back the parameter without any format.
* The only exception is a `null` value which will be formatted using [[nullDisplay]].
* @param mixed $value the value to be formatted. * @param mixed $value the value to be formatted.
* @return string the formatted result. * @return string the formatted result.
*/ */
...@@ -342,14 +343,15 @@ class Formatter extends Component ...@@ -342,14 +343,15 @@ class Formatter extends Component
/** /**
* Formats the value as an image tag. * Formats the value as an image tag.
* @param mixed $value the value to be formatted. * @param mixed $value the value to be formatted.
* @param string $altText an optional `alt`-tag to be added to the image.
* @return string the formatted result. * @return string the formatted result.
*/ */
public function asImage($value) public function asImage($value, $altText = '')
{ {
if ($value === null) { if ($value === null) {
return $this->nullDisplay; return $this->nullDisplay;
} }
return Html::img($value); return Html::img($value, ['alt' => $altText]);
} }
/** /**
......
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