Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
Created March 5, 2014 13:13
Show Gist options
  • Select an option

  • Save GreatPotato/9366899 to your computer and use it in GitHub Desktop.

Select an option

Save GreatPotato/9366899 to your computer and use it in GitHub Desktop.
Customize flash messages in LemonStand
<?php
class Advantage {
public static function show_error()
{
if (array_key_exists('system', Phpr::$session->flash->flash))
{
$system_message = Phpr::$session->flash['system'];
if (strpos($system_message, 'flash_partial') !== false && !array_key_exists('error', Phpr::$session->flash->flash))
{
$partial_name = substr($system_message, 14);
$success_message = array_key_exists('success', Phpr::$session->flash->flash) ? Phpr::$session->flash->flash['success'] : null;
Cms_Controller::get_instance()->render_partial($partial_name, array('message'=>$success_message));
Phpr::$session->flash->now();
return;
}
}
return static::flash();
}
private static function flash()
{
$result = null;
foreach( Phpr::$session->flash as $type => $message )
{
if ($type == 'system')
continue;
switch ($type) {
case 'system':
$type = 'info';
$prefix = '<strong>Hmm, the computer is struggling!</strong>';
break;
case 'error':
$type = 'danger';
$prefix = '<strong>Uh oh, there was a problem!</strong>';
break;
default:
$type = 'warning';
$prefix = '<strong>There seems to be a problem</strong>';
}
$result .= '<div class="alert alert-'.$type.'"><button class="close icon-cross4" data-dismiss="alert"></button>' . $prefix . ' ' . h($message) . '</div>';
}
Phpr::$session->flash->now();
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment