« CSS Typography Template Winters coming, WrapUp! »
Tags: CMS, Code, CodeIgniter, notifications
Posted in Code, CodeIgniter, PHP
Often, I find I need to send notifications to the user (webpage) during server code. This may be a warning, notification, or a message that an action has hapend. If you’re using a MVC framework it’s not practical to exit running code or echo out the message. From a User Interface perspective it is also imperative that the user knows where to look for these notifications and what they mean.
This all lead me to develop a re-usable solution to drop into any project. As all most all of the sites I work on use CodeIgniter now, once again a CI Library was the obvious choice. Oi is notifications management system that, when stripped to its basic behaviour, has two uses.
Pretty Simple. Added to that it will also remember notices between page redirects. So if you add a notice and then reach some code that triggers a redirect the notice will be displayed on the next page.
The library is now in its second incarnation. My original version supported three types of notices
Each message would be returned as separate elements with a relevant class representing the type. This was pretty sufficient for most applications but there were times when I wanted to add more attributes (classes, titles, ids) or just needed another ‘type’.
So the new version uses the magic php method __call to provide an unlimited number of ‘types’ via the method $oi->add_{type}($string);
e.g.
$this->oi->add_message('Well Done');
or
$this->oi->add_reallylongandimpressivesupertype('Hello');
More examples and documentation available in the code section
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.