-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from froschdesign/hotfix/docs/rework
Updates documentation to add introduction, basic usage and examples for configuration, Bootstrap, application-wide layout
- Loading branch information
Showing
8 changed files
with
239 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Basic Usage | ||
|
||
In the following example, a flash message is set in a controller action and the rendering is done after a redirect. | ||
|
||
## Create a Flash Message | ||
|
||
Store a message in the messenger of a controller action, e.g. `module/Album/Controller/AlbumController.php`: | ||
|
||
```php | ||
namespace Album\Controller; | ||
|
||
use Laminas\Mvc\Controller\AbstractActionController; | ||
|
||
class AlbumController extends AbstractActionController | ||
{ | ||
public function editAction() | ||
{ | ||
// Do some work… | ||
|
||
// Add success message | ||
$this->flashMessenger()->addSuccessMessage( | ||
'Album created successfully.' | ||
); | ||
|
||
// Redirect | ||
return $this->redirect()->toRoute('album'); | ||
} | ||
} | ||
``` | ||
|
||
## Render a Flash Message | ||
|
||
Render all flash messages in a view script, e.g. `module/Album/view/album/album/index.phtml`: | ||
|
||
```php | ||
<?= $this->flashMessenger()->render() ?> | ||
``` | ||
|
||
Output: | ||
|
||
```html | ||
<ul class="success"><li>Album created successfully.</li></ul> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Set Application-Wide Layout | ||
|
||
The format for the `FlashMessenger` view helper can be configured for an entire application as well as all uses of the helper. | ||
|
||
`Laminas\View\Helper\Service\FlashMessengerFactory` checks the application | ||
configuration and creates the view helper with the given format options. | ||
|
||
## Set the Format for All Namespaces | ||
|
||
Add the following lines to the local or global configuration file, e.g. `config/autoload/global.config.php`: | ||
|
||
```php | ||
return [ | ||
'view_helper_config' => [ | ||
'flashmessenger' => [ | ||
'message_open_format' => '<p%s>', | ||
'message_close_string' => '</p>', | ||
'message_separator_string' => '<br>', | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
## Set Formats Individually for Namespaces | ||
|
||
INFO: **New Feature** | ||
Available since version 1.8.0 | ||
|
||
Add the following lines to the local or global configuration file, e.g. `config/autoload/global.config.php`: | ||
|
||
```php | ||
return [ | ||
'view_helper_config' => [ | ||
'flashmessenger' => [ | ||
'default' => [ | ||
'message_open_format' => '<p%s>', | ||
'message_close_string' => '</p>', | ||
'message_separator_string' => '<br>', | ||
'classes' => 'custom-default example-class', | ||
], | ||
'success' => [ | ||
'message_open_format' => '<p%s>', | ||
'message_close_string' => '</p>', | ||
'message_separator_string' => '<br>', | ||
'classes' => 'custom-success example-class', | ||
], | ||
'warning' => [ | ||
// … | ||
], | ||
'error' => [ | ||
// … | ||
], | ||
'info' => [ | ||
// … | ||
], | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
If the default unordered list should be retained, then set only the classes: | ||
|
||
```php | ||
return [ | ||
'view_helper_config' => [ | ||
'flashmessenger' => [ | ||
'default' => [ | ||
'classes' => 'custom-default', | ||
], | ||
'success' => [ | ||
'classes' => 'custom-success', | ||
], | ||
'warning' => [ | ||
'classes' => 'custom-warning', | ||
], | ||
'error' => [ | ||
'classes' => 'custom-error', | ||
], | ||
'info' => [ | ||
'classes' => 'custom-info', | ||
], | ||
], | ||
], | ||
]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Use Alerts from Bootstrap | ||
|
||
To use the syntax of the [alerts from the Bootstrap CSS framework](https://getbootstrap.com/docs/5.2/components/alerts/) for the output of the view helper, the configuration of the message format must be adjusted. | ||
|
||
To do that, add the following lines to the local or global configuration file, e.g. `config/autoload/global.config.php`: | ||
|
||
```php | ||
return [ | ||
'view_helper_config' => [ | ||
'flashmessenger' => [ | ||
'default' => [ | ||
'message_open_format' => '<div%s role="alert">', | ||
'message_close_string' => '</div>', | ||
'message_separator_string' => '</div><div%s role="alert">', | ||
'classes' => 'alert alert-primary', | ||
], | ||
'success' => [ | ||
'message_open_format' => '<div%s role="alert">', | ||
'message_close_string' => '</div>', | ||
'message_separator_string' => '</div><div%s role="alert">', | ||
'classes' => 'alert alert-success', | ||
], | ||
'warning' => [ | ||
'message_open_format' => '<div%s role="alert">', | ||
'message_close_string' => '</div>', | ||
'message_separator_string' => '</div><div%s role="alert">', | ||
'classes' => 'alert alert-success', | ||
], | ||
'error' => [ | ||
'message_open_format' => '<div%s role="alert">', | ||
'message_close_string' => '</div>', | ||
'message_separator_string' => '</div><div%s role="alert">', | ||
'classes' => 'alert alert-danger', | ||
], | ||
'info' => [ | ||
'message_open_format' => '<div%s role="alert">', | ||
'message_close_string' => '</div>', | ||
'message_separator_string' => '</div><div%s role="alert">', | ||
'classes' => 'alert alert-info', | ||
], | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
This will set the format [for all uses of the view helper](application-wide-layout.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This Is Only a Placeholder | ||
|
||
The content of this page can be found under: | ||
|
||
https://github.com/laminas/documentation-theme/blob/master/theme/pages/installation.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Introduction | ||
|
||
Giving feedback to a user is an important part of a good application. | ||
Flash messages provide notifications to the user, such as for successful form submissions, failure to save data in the database, and incorrect authentication credentials. | ||
A message is created at the end of one request, and shown to the user in the next request. | ||
Flash messages are self-expiring and session-based. | ||
|
||
To create and expose flash messages in a laminas-mvc-based application, this packages provides: | ||
|
||
- [a controller plugin to create and retrieve messages](controller-plugin.md) | ||
- [a view helper to render the messages](view-helper.md) | ||
|
||
A flash message is set in a controller and then rendered in a view script. | ||
|
||
## Namespaces | ||
|
||
The controller plugin and the view helper support different types of messages: | ||
|
||
- `default` | ||
- `info` | ||
- `success` | ||
- `warning` | ||
- `error` | ||
|
||
These namespaces provide support for handling different output formats. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters