Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/21-docs-fixes'
Browse files Browse the repository at this point in the history
Close #21
Fixes #20
  • Loading branch information
weierophinney committed Jun 5, 2018
2 parents 6308253 + 0a10e5b commit 004fd91
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 5 deletions.
98 changes: 98 additions & 0 deletions docs/book/flash-messenger-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# FlashMessenger Controller Plugin

The `FlashMessenger` controller plugin is designed to create and retrieve
self-expiring, session-based messages. It exposes a number of methods:

- `setSessionManager(Zend\Session\ManagerInterface $manager) : FlashMessenger`:
Allows you to specify an alternate session manager, if desired.

- `getSessionManager() : Zend\Session\ManagerInterface`: Allows you to retrieve
the session manager registered.

- `getContainer() : Zend\Session\Container`: Returns the
`Zend\Session\Container` instance in which the flash messages are stored.

- `setNamespace(string $namespace = 'default') : FlashMessenger`:
Allows you to specify a specific namespace in the container in which to store
or from which to retrieve flash messages.

- `getNamespace() : string`: retrieves the name of the flash message namespace.

- `addMessage(string $message) : FlashMessenger`: Allows you to add a message to
the current namespace of the session container.

- `hasMessages() : bool`: Lets you determine if there are any flash messages
from the current namespace in the session container.

- `getMessages() : array`: Retrieves the flash messages from the current
namespace of the session container

- `clearMessages() : bool`: Clears all flash messages in current namespace of
the session container. Returns `true` if messages were cleared, `false` if
none existed.

- `hasCurrentMessages() : bool`: Indicates whether any messages were added
during the current request.

- `getCurrentMessages() : array`: Retrieves any messages added during the
current request.

- `clearCurrentMessages() : bool`: Removes any messages added during the current
request. Returns `true` if current messages were cleared, `false` if none
existed.

- `clearMessagesFromContainer() : bool`: Clear all messages from the container.
Returns `true` if any messages were cleared, `false` if none existed.

This plugin also provides four meaningful namespaces, namely: `INFO`, `ERROR`,
`WARNING`, and `SUCCESS`. The following functions are related to these
namespaces:

- `addInfoMessage(string $message): FlashMessenger`: Add a message to "info"
namespace.

- `hasCurrentInfoMessages() : bool`: Check to see if messages have been added to
"info" namespace within this request.

- `addWarningMessage(string $message) : FlashMessenger`: Add a message to
"warning" namespace.

- `hasCurrentWarningMessages() : bool`: Check to see if messages have been added
to "warning" namespace within this request.

- `addErrorMessage(string $message) : FlashMessenger`: Add a message to "error"
namespace.

- `hasCurrentErrorMessages() : bool`: Check to see if messages have been added
to "error" namespace within this request.

- `addSuccessMessage(string $message) : FlashMessenger`: Add a message to
"success" namespace.

- `hasCurrentSuccessMessages() :bool`: Check to see if messages have been added
to "success" namespace within this request.

Additionally, the `FlashMessenger` implements both `IteratorAggregate` and
`Countable`, allowing you to iterate over and count the flash messages in the
current namespace within the session container.

### Examples

```php
public function processAction()
{
// ... do some work ...
$this->flashMessenger()->addMessage('You are now logged in.');
return $this->redirect()->toRoute('user-success');
}

public function successAction()
{
$return = ['success' => true];
$flashMessenger = $this->flashMessenger();
if ($flashMessenger->hasMessages()) {
$return['messages'] = $flashMessenger->getMessages();
}
return $return;
}
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# FlashMessenger
# FlashMessenger View Helper

The `FlashMessenger` helper is used to render the messages of the
[FlashMessenger MVC plugin](http://zendframework.github.io/zend-mvc-plugin-flashmessenger/).
[FlashMessenger controller plugin](flash-messenger-plugin.md).

## Basic Usage

Expand Down
7 changes: 4 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
docs_dir: docs/book
site_dir: docs/html
pages:
- index.md
- View Helper: flash-messenger-view-helper.md
- Home: index.md
- "Controller Plugin": flash-messenger-plugin.md
- "View Helper": flash-messenger-view-helper.md
site_name: zend-mvc-plugin-flashmessenger
site_description: 'zend-mvc-plugin-flashmessenger: Flash messages for zend-mvc controllers'
site_description: 'Plugin for creating and exposing flash messages via zend-mvc controllers'
repo_url: 'https://github.com/zendframework/zend-mvc-plugin-flashmessenger'
copyright: 'Copyright (c) 2005-2018 <a href="https://www.zend.com/">Zend Technologies USA Inc.</a>'

0 comments on commit 004fd91

Please sign in to comment.