In this section, we'll use our existing variables in bones to allow us to show alert messages to our users.
1. Open
lib/bones.php
and create a new function calleddisplay_alert()
. This function will be called to see if thealert
variable is set. If thealert
variable is set, we will echo some HTML to show the alert box on the layout.public function display_alert($variable = 'error') { if (isset($this->vars[$variable])) { return "<div class='alert alert-" . $variable . "'><a class='close' data-dismiss='alert'>x</a>" . $this- >vars[$variable] . "</div>"; } }
2. Add code to
layout.php
, right inside of the containerdiv
to display the Flash call thedisplay_flash
function.<div class="container"> <?php echo $this->display_alert('error'); ?> <?php echo $this->display_alert('success'); ?> <?php include($this->content); ?> </div>
3. Now that we've added these Flash messages, let's go back to our...