I did it again. It’s a new library called Postal (don’t tell me how I came up with this title…). It’s a library that will allow you to pass informational messages between requests.
This library is using the CodeIgniter’s session library to pass the messages between the requests. As usual, it all started from using another library. The Jens Seger Message library (https://github.com/jenssegers/codeigniter-message-library) was a good library, but I thought it needed improvements. But working with CodeIgniter 3, I told myself why not create another library and start all over.
So, meet my new library, CodeIgniter Postal (https://github.com/avenirer/CodeIgniter-Postal).
This one is simply to use. You only have to copy the Postal.php into your application/libraries, do a $this->load->library(‘postal’); and you’re ready to go.
You can add messages by using the add() method:
$this->postal->add("An error has occurred", "error"); $this->postal->add("The page was updated", "success"); $this->postal->add("How are you?", "message");
You can actually group the messages (and the delimiters between the message groups) in any way you need to by creating a postal.php file inside the application/config library and writing something like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $config['message_types'] = array( 'jumacara' => array('<div class="whatever">', '</div>'), 'bacabaca' => array('<div class="classy-name">', '</div>'), 'tikituku' => array('<div class="you-want">', '</div>'));
If you do this, the message groups from the configuration file will be used and not “success”, “error”, nor “message”.
You can display the messages in any other controller by using the get() method:
echo $this->postal->get(); // THIS WILL RETURN ALL THE MESSAGES AS A STRING echo $this->postal->get('error'); // THIS WILL ONLY RETURN THE MESSAGES FROM A SPECIFIC GROUP OF MESSAGES echo $this->postal->get(array('success','error')); // THIS WILL ONLY RETURN THE MESSAGES FROM SPECIFIED GROUPS $messages = $this->postal->get(NULL, TRUE); // THIS WILL RETURN ALL MESSAGES AS AN ARRAY, WITHOUT ANY MESSAGE DELIMITERS $messages = $this->postal->get('error', TRUE); // THIS WILL ONLY RETURN THE MESSAGES FROM A SPECIFIC GROUP OF MESSAGES, WITHOUT ANY MESSAGE DELIMITERS $messages = $this->postal->get(array('success','error'), TRUE); // THIS WILL ONLY RETURN THE MESSAGES FROM SPECIFIED GROUPS, WITHOUT ANY MESSAGE DELIMITERS
Simple, isn’t it?
You can read more about it on the Github page.
I sure hope you will like it.
Interesting script. Thanks for sharing
I’m wondering if this library could be used to share messages amongs members working on the same platform/Project. Could the messages addressed to specific users? Thanks again for the great tutorial…I’m learning a lot following you.
It would indeed be a useful addition to also send email when a message is created. Will look into it.
MegaMenu with images and video
Template System with theming functinality
Paypal Payment in CI
integrate projects from github to CI
CLI updated codes
Blogging system using parsedown/markdown
CKEditor on admin pages
Extend Unit testing(Not using another testing framework instead more functions additional from default)
Profiling, with benchmark and checker of variables
Dynamic Environment using php not in HTACCESS
Browse Manager in PHP
Progressive Enhancment in Codeigniter (huge and big topic)
Chating system in codeigniter
adding smiley or emoticons without using smiley libray since it was stated it would be deprecated in the future
Wow. These are great subjects. Thank you very much.