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
2bff5f80
Commit
2bff5f80
authored
Nov 20, 2013
by
Kartik Visweswaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alert types for flash messages are now configurable.
Each flash variable can be mapped to a bootstrap alert type through a configuration array passed to this widget.
parent
8ff4c3d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
Alert.php
apps/advanced/frontend/widgets/Alert.php
+18
-11
No files found.
apps/advanced/frontend/widgets/Alert.php
View file @
2bff5f80
...
...
@@ -21,9 +21,18 @@ namespace frontend\widgets;
class
Alert
extends
\yii\bootstrap\Widget
{
/**
* @var array the allowed bootstrap alert types.
* @var array the alert types configuration for the flash messages.
* This array is setup as $key => $value, where:
* - $key is the name of the session flash variable
* - $value is the bootstrap alert type (i.e. danger, success, info, warning)
*/
public
$allowedTypes
=
[
'error'
,
'danger'
,
'success'
,
'info'
,
'warning'
];
public
$alertTypes
=
[
'error'
=>
'danger'
,
'danger'
=>
'danger'
,
'success'
=>
'success'
,
'info'
=>
'info'
,
'warning'
=>
'warning'
];
/**
* @var array the options for rendering the close button tag.
...
...
@@ -37,15 +46,13 @@ class Alert extends \yii\bootstrap\Widget
$appendCss
=
isset
(
$this
->
options
[
'class'
])
?
' '
.
$this
->
options
[
'class'
]
:
''
;
foreach
(
$flashes
as
$type
=>
$message
)
{
if
(
in_array
(
$type
,
$this
->
allowedTypes
))
{
$this
->
options
[
'class'
]
=
((
$type
===
'error'
)
?
'alert-danger'
:
'alert-'
.
$type
)
.
$appendCss
;
echo
\yii\bootstrap\Alert
::
widget
([
'body'
=>
$message
,
'closeButton'
=>
$this
->
closeButton
,
'options'
=>
$this
->
options
]);
$session
->
removeFlash
(
$type
);
}
$this
->
options
[
'class'
]
=
'alert-'
.
$this
->
alertTypes
[
$type
]
.
$appendCss
;
echo
\yii\bootstrap\Alert
::
widget
([
'body'
=>
$message
,
'closeButton'
=>
$this
->
closeButton
,
'options'
=>
$this
->
options
]);
$session
->
removeFlash
(
$type
);
}
parent
::
init
();
}
...
...
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