In the course of executing a program you need to report errors / success messages to the user. But you don’t want to mix your code with HTML, right? (A quick explanation on separating presentation from business / data logic.)
So here’s what I use:
-
span class=”coMULTI”>/**
-
* Factory function, ensures that
-
* MessageStack is a singleton
-
*//**
-
* Returns stack contents
-
*/
When I want to report something I call:
-
$messageStack = MessageStack::create();
-
$messageStack->add(‘ok’, ‘Record saved.’);
Then in your main file you run this:
-
span class=”st0″>"messages", $messageStack->get());
Include this into template (preferably the part that is included into every template):
-
-
-
<div class="message {$type}"></div>
-
-
And then in css, define all message types:
Question
Do you use something like this or something more clever? Share your wisdom :-)
-