Message Library |
[eluser]n0xie[/eluser]
Message Library The CodeIgniter Message Library is a small, simple library to unify the way you pass messages to a view. It is largely a rewrite of Adam Jackett's message library to suit my personal needs. It allows for single, multiple or groups of messages. You can set a message to appear on the current page, or on the next page, such as after a redirect, or even after several redirects. It will only clear the message the moment it has been displayed. You can change the way the message looks by adding a view partial with the same name as the message. If no named view is present, it will default to a default message view partial. If no default message view partial is present, it will try to fall back to a config file. If that isn't present it will just show the message without any markup, which might be preferable if you want to pass the message to javascript, in particular, something like a jQuery Growl plugin. Basic usage Set a message Code: $this->message->set('notice','this is just a notice'); Set an array of messages Code: $data = array( Return all messages Code: $messages = $this->message->get(); Return a group of messages Code: $messages = $this->message->get('notice'); Show all messages Code: echo $this->message->display(); Show a group of messages Code: echo $this->message->display('notice'); I hope it is useful to someone, and let me know if you find any bugs or have any feature requests. Download CodeIgniter Message Library
[eluser]2think[/eluser]
n0xie, Thanks for the lib. Am I correct that this is similar to the built-in flashdata functionality? I'm thinking it is and love the use of the view partials. Also, where you stated "...group of messages", did you mean "particular message" or something like that?
[eluser]n0xie[/eluser]
It is actually exactly like the flashdata functionality but it is meant as a replacement, since I sometimes ran into situations that I wanted to show a message, without a redirect. Obviously you could pass it to a the view, but then you'd have to check somewhere if a message was set, or if flashdata was available. I use this library to abstract that part away and keep one syntax for all messages. The group message comes into play if you have a page where you want to show messages in different places. For instance you could have a 'error' group as well as a 'notice' group. On your page you might want to show the errors near a form (say some update didn't go through because the user didn't have certain rights) but at the same time, you want to show that some other action did occur (like a user came online if you were using something like a chatbox). You can easily do this using: Code: echo $this->message->display('notice');
[eluser]2think[/eluser]
Got it, so the term "group message" is like "category" of message? Ok, makes sense and very powerful. I really like your functionality of the views being called in a cascading manner, I'll play with this and report any issues. Thx again |
Welcome Guest, Not a member yet? Register Sign In |