Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
e1319c9b
Commit
e1319c9b
authored
Oct 19, 2014
by
Nobuo Kihara
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into docs-ja-2014-10-18
parents
865100ae
6ab10bcd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
helper-overview.md
docs/guide/helper-overview.md
+18
-13
No files found.
docs/guide/helper-overview.md
View file @
e1319c9b
...
@@ -15,12 +15,13 @@ use yii\helpers\Html;
...
@@ -15,12 +15,13 @@ use yii\helpers\Html;
echo
Html
::
encode
(
'Test > test'
);
echo
Html
::
encode
(
'Test > test'
);
```
```
> Note: To support [
extending helper classes](#extend
ing-helper-classes), Yii breaks each core helper class
> Note: To support [
customizing helper classes](#customiz
ing-helper-classes), Yii breaks each core helper class
into two classes: a base class (e.g.
`BaseArrayHelper`
) and a concrete class (e.g.
`ArrayHelper`
).
into two classes: a base class (e.g.
`BaseArrayHelper`
) and a concrete class (e.g.
`ArrayHelper`
).
When you use a helper, you should only use the concrete version and never use the base class.
When you use a helper, you should only use the concrete version and never use the base class.
## Core Helper Classes
Core Helper Classes
-------------------
The following core helper classes are provided in the Yii releases:
The following core helper classes are provided in the Yii releases:
...
@@ -39,19 +40,21 @@ The following core helper classes are provided in the Yii releases:
...
@@ -39,19 +40,21 @@ The following core helper classes are provided in the Yii releases:
-
VarDumper
-
VarDumper
## Extending Helper Classes
Customizing Helper Classes <a name="customizing-helper-classes"></a>
--------------------------
To custom a core helper class (e.g.
`yii\helpers\ArrayHelper`
), you should extend from its corresponding base class
To customize a core helper class (e.g.
[
[yii\helpers\ArrayHelper
]
]), you should create a new class extending
(e.g.
`yii\helpers\BaseArrayHelper`
) and name your class the same as the corresponding concrete class
from the helpers corresponding base class (e.g.
[
[yii\helpers\BaseArrayHelper
]
]) and name your class the same
(e.g.
`yii\helpers\ArrayHelper`
), including its namespace.
as the corresponding concrete class (e.g.
[
[yii\helpers\ArrayHelper
]
]), including its namespace. This class
will then be set up to replace the original implementation of the framework.
The following example shows how to customize the
[
[yii\helpers\ArrayHelper::merge()|merge()
]
] method of the
The following example shows how to customize the
[
[yii\helpers\ArrayHelper::merge()|merge()
]
] method of the
[
[yii\helpers\ArrayHelper
]
] class:
[
[yii\helpers\ArrayHelper
]
] class:
```
php
```
php
namespace
yii\helpers
;
<?php
use
yii\helpers\BaseArrayHelper
;
namespace
yii\helpers
;
class
ArrayHelper
extends
BaseArrayHelper
class
ArrayHelper
extends
BaseArrayHelper
{
{
...
@@ -62,14 +65,16 @@ class ArrayHelper extends BaseArrayHelper
...
@@ -62,14 +65,16 @@ class ArrayHelper extends BaseArrayHelper
}
}
```
```
Save your class in a file named
`ArrayHelper.php`
. The file can be in any directory,
such as
`@app/components`
.
Save your class in a file named
`ArrayHelper.php`
. The file can be in any directory,
for example
`@app/components`
.
Next, in your application's
[
entry script
](
structure-entry-scripts.md
)
, add the following line of code
Next, in your application's
[
entry script
](
structure-entry-scripts.md
)
, add the following line of code
after including the
`yii.php`
file:
after including the
`yii.php`
file to tell the
[
Yii class autoloader
](
concept-autoloading.md
)
to load your custom
class instead of the original helper class from the framework:
```
php
```
php
Yii
::
$classMap
[
'yii\helpers\ArrayHelper'
]
=
'
path/to
/ArrayHelper.php'
;
Yii
::
$classMap
[
'yii\helpers\ArrayHelper'
]
=
'
@app/components
/ArrayHelper.php'
;
```
```
The above line instructs the
[
Yii class autoloader
](
concept-autoloading.md
)
to load your version of the helper
Note that customizing of helper classes is only useful if you want to change the behavior of an existing function
class, instead of the one included in the Yii releases.
of the helpers. If you want to add additional functions to use in your application you may better create a separate
helper for that.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment