-
Notifications
You must be signed in to change notification settings - Fork 10
Message
Stefano Azzolini edited this page Aug 29, 2014
·
1 revision
The Message module allow you pass messages between requests.
Getting a message (or all) delete them from session.
Message::add('error',"This is an error.");
Message::add('info',"Testing messages!.");
Message::add('error',"Another error?.");
var_dump(
Message::all('error'),
Message::all(),
Message::all()
);
array(2) {
[0]=> string(17) "This is an error."
[1]=> string(14) "Another error?"
}
array(1) {
["info"]=> array(1) {
[0]=> string(18) "Testing messages!."
}
}
array(0) {
}
Messages must be registered to a container
Message::add('error',"There was an error!");
Message::add('error',"Another one!");
Get (and remove from stash) all the messages.
$all_messages = Message::all();
print_r(Message::all());
false
You can retrieve only messages of a specified container.
foreach( Message::all('error') as $error ){
echo "$error\n";
};
Message::clear();
You can add a read-only accessor as a global view variable.
View::addGlobal('Message', Message::readOnly() );
Now you can access messages directly in view templates via the Message
global.
{% for type,messages in Message.all() %}
{% for text in messages %}
<div class="errors {{ type }}">{{ text }}</div>
{% endfor %}
{% endfor %}
The messages are one-shot only, only consumed they are deleted from the stash.
Core is maintained by using the Semantic Versioning Specification (SemVer).
Copyright 2014-2016 Caffeina srl under the MIT license.
http://caffeina.com