I am pleased to announce my latest CodeIgniter Spark, MessageCI. MessageCI is quite possibly the simplest messaging library currently available for CodeIgniter. It makes no assumptions about your ORM or database code, application themes, CSS, views, models or anything else. It simply gets out of your way to you can get down to business.
Download MessageCI from Github
Set a Message
Detect an event to which you want to alert the user. For this example, we will assume a form has been POSTed and form validation failed.
1 2 3 4 5 6 7 8 9 10 11 12 |
// Form validation failed... if( ! $this->form_validation->run()) { $errors = $this->form_validation->error_array(); foreach($errors as $error) { $this->messageci->set($error, 'error'); } // Redirect to some page to show the error message redirect('/testpage/method'); } |
Display a Message
Display a message to the user in a view. CSS styles are configured via the config file to decouple logic from presentation. If there are no messages set, nothing happens, so you can safely embed this code in every view without worrying about detecting messages.
1 |
$this->messageci->display(); |