Skip to content

Messaging

bbaisley edited this page Jan 25, 2013 · 1 revision

Messaging

Basecoat comes with a basic user message display system that includes 3 display types: info, warn and error. The Messages class uses the Content class when processing messages for display. An instance of the messages class is automatically created when Basecoat is instantiated and can be referenced using $basecoat->messages. Basecoat comes with a message template that is used by default and is in templates/messages.tpl.php in the Basecoat template directory.

Messages are stored in the session so that they are not lost if there is a page redirect or error. Any messages that have been registered will automatically be displayed on the next normal full page render via the $basecoat->processRequest() method. Messages can also be output on demand by calling the display() function. Any layout set to display messages should have an output line <?php echo $this->messages; ?>. If this code is not present anywhere, messages will not be displayed and will be lost.

Registering a message for display is done by calling the appropriate function for the type of message to output. Each function can be called multiple times. Similar messages will automatically be aggregated when displayed.

setTemplate($tpl_file)
Set the template file, relative to template directory, for the messaging class to use.

info($message)
Add an informational message.

warn($message)
Add an warning/alert message.

error($message)
Add an error message.

get($ms_type=null)
Retrieve the list of messages currently set. Optionally retrieve messages of specific type.

display($view, $clear=true)
Process the current set of messages and add to the passed View controller. Messages are cleared by default. This function is automatically called by Basecoat before generating the final output.

clear($msg_type=null)
Clear all messages currently set, or optionally pass a message type (info, warn, error) to clear.

Clone this wiki locally