![]() |
cutelyst 5.0.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Manage status messages over multiple requests stored in the Session. More...
#include <Cutelyst/Plugins/StatusMessage>

Public Member Functions | |
| StatusMessage (Application *parent) | |
| virtual | ~StatusMessage () override |
| QString | errorMgStashKey () const noexcept |
| QString | sessionPrefix () const noexcept |
| void | setErrorMgStashKey (const QString &errorMgStashKey) |
| void | setSessionPrefix (const QString &sessionPrefix) |
| void | setStatusMsgStashKey (const QString &statusMsgStashKey) |
| void | setTokenParam (const QString &tokenParam) |
| QString | statusMsgStashKey () const noexcept |
| QString | tokenParam () const noexcept |
| Public Member Functions inherited from Cutelyst::Plugin | |
| Plugin (Application *parent) | |
Static Public Member Functions | |
| static QString | error (Context *c, const QString &msg) |
| static ParamsMultiMap | errorQuery (Context *c, const QString &msg, ParamsMultiMap query={}) |
| static void | load (Context *c) |
| static QString | status (Context *c, const QString &msg) |
| static ParamsMultiMap | statusQuery (Context *c, const QString &msg, ParamsMultiMap query={}) |
Protected Member Functions | |
| virtual bool | setup (Application *app) override |
The StatusMessage plugin can be used to generate status messages that are saved to the user’s session that will be available over multiple requests. It distinguishes between normal status messages set via status() or statusQuery() and error messages set via error() or errorQuery(). The static load() method loads the status messages into the Context::stash() at appropriate places like the Auto() method of the root controller. The status messages will be identified by a message id put into the URL query of the request URL using the "mid" query key by default.
Load the plugin in your applications’s init method:
Then use for example your root controller’s Auto method to load the messages into the stash:
In another controller we can now generate a status and/or error message:
Definition at line 84 of file statusmessage.h.
|
explicit |
Constructs a new StatusMessage object with the given Application parent.
Definition at line 43 of file statusmessage.cpp.
References Cutelyst::Plugin::Plugin().
Referenced by errorMgStashKey(), sessionPrefix(), setErrorMgStashKey(), setSessionPrefix(), setStatusMsgStashKey(), setTokenParam(), statusMsgStashKey(), and tokenParam().
|
overridevirtual |
Destroys the StatusMessage object.
Definition at line 50 of file statusmessage.cpp.
|
staticnodiscard |
Saves an error message msg and returns the generated message id (mid).
Definition at line 142 of file statusmessage.cpp.
References Cutelyst::Session::setValue().
|
nodiscardnoexcept |
Returns the name of the stash key where error messages are loaded when load() is called. Defaults to "error_msg".
Definition at line 91 of file statusmessage.cpp.
References StatusMessage().
Referenced by setErrorMgStashKey().
|
staticnodiscard |
Saves an error message msg returning query parameters with the generated message id (mid) and it's token combined with query.
Definition at line 155 of file statusmessage.cpp.
References Cutelyst::Session::setValue().
|
static |
Load both messages that match the token param (mid=###) into the stash for display by the view.
Definition at line 103 of file statusmessage.cpp.
References Cutelyst::Session::deleteValues(), Cutelyst::Request::queryParam(), Cutelyst::Context::request, Cutelyst::Context::setStash(), and Cutelyst::Session::value().
|
nodiscardnoexcept |
Returns the key prefix inside Session where messages will be stored. Defaults to "status_mg".
Definition at line 55 of file statusmessage.cpp.
References StatusMessage().
Referenced by setSessionPrefix().
| void StatusMessage::setErrorMgStashKey | ( | const QString & | errorMgStashKey | ) |
Sets the name of the stash key where error messages are loaded when load() is called. Defaults to "error_msg".
Definition at line 97 of file statusmessage.cpp.
References StatusMessage(), and errorMgStashKey().
| void StatusMessage::setSessionPrefix | ( | const QString & | sessionPrefix | ) |
Sets the key prefix inside Session where messages will be stored. Defaults to "status_msg".
Definition at line 61 of file statusmessage.cpp.
References StatusMessage(), and sessionPrefix().
| void StatusMessage::setStatusMsgStashKey | ( | const QString & | statusMsgStashKey | ) |
Sets the name of the stash key where "success" status messages are loaded when load() is called. Defaults to "status_msg".
Definition at line 85 of file statusmessage.cpp.
References StatusMessage(), and statusMsgStashKey().
| void StatusMessage::setTokenParam | ( | const QString & | tokenParam | ) |
Sets the name of the URL query parameter that holds the token on the page where you want to retrieve/display the status message. Defaults to "mid".
Definition at line 73 of file statusmessage.cpp.
References StatusMessage(), and tokenParam().
|
overrideprotectedvirtual |
Reimplemented from Plugin::setup().
Reimplemented from Cutelyst::Plugin.
Definition at line 198 of file statusmessage.cpp.
References Cutelyst::Application::postForked().
|
staticnodiscard |
Saves a status message msg and returns the generated message id (mid).
Definition at line 170 of file statusmessage.cpp.
References Cutelyst::Session::setValue().
|
nodiscardnoexcept |
Returns the name of the stash key where "success" status messages are loaded when load() is called. Defaults to "status_msg".
Definition at line 79 of file statusmessage.cpp.
References StatusMessage().
Referenced by setStatusMsgStashKey().
|
staticnodiscard |
Saves an status message msg returning query parameters with the generated message id (mid) and it's token combined with query.
Definition at line 183 of file statusmessage.cpp.
References Cutelyst::Session::setValue().
|
nodiscardnoexcept |
Returns the name of the URL query parameter that holds the token on the page where you want to retrieve/display the status message. Defaults to "mid".
Definition at line 67 of file statusmessage.cpp.
References StatusMessage().
Referenced by setTokenParam().