├── .gitignore ├── classes ├── message.php └── message │ └── core.php ├── config └── userguide.php ├── guide └── message │ ├── index.md │ └── menu.md ├── readme.md └── views └── message └── basic.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore hidden files 2 | .* 3 | 4 | # Not this 5 | !.gitignore 6 | -------------------------------------------------------------------------------- /classes/message.php: -------------------------------------------------------------------------------- 1 | type = $type; 46 | $this->message = $message; 47 | } 48 | 49 | /** 50 | * Clears the message from the session. 51 | */ 52 | public static function clear() 53 | { 54 | Session::instance()->delete('flash_message'); 55 | } 56 | 57 | /** 58 | * Displays the message. 59 | * 60 | * @param string Name of the view 61 | * @return string Message to string 62 | */ 63 | public static function display($view = null) 64 | { 65 | $html = ""; 66 | $msg = self::get(); 67 | 68 | if($msg) 69 | { 70 | if ($view === null) 71 | { 72 | $view = self::$default; 73 | } 74 | 75 | self::clear(); 76 | $html = View::factory($view)->set('message', $msg)->render(); 77 | } 78 | 79 | return $html; 80 | } 81 | 82 | /** 83 | * The same as display - used to mold to Kohana standards. 84 | * 85 | * @param string Name of the view 86 | * @return string HTML for message 87 | */ 88 | public static function render($view = null) 89 | { 90 | return self::display($view); 91 | } 92 | 93 | /** 94 | * Gets the current message. 95 | * 96 | * @return mixed The message or FALSE 97 | */ 98 | public static function get() 99 | { 100 | return Session::instance()->get('flash_message', FALSE); 101 | } 102 | 103 | /** 104 | * Sets a message. 105 | * 106 | * @param string Type of message 107 | * @param mixed Array/String for the message 108 | */ 109 | public static function set($type, $message) 110 | { 111 | Session::instance()->set('flash_message', new Message($type, $message)); 112 | } 113 | 114 | /** 115 | * Sets an error message. 116 | * 117 | * @param mixed String/Array for the message(s) 118 | */ 119 | public static function error($message) 120 | { 121 | self::set(Message::ERROR, $message); 122 | } 123 | 124 | /** 125 | * Sets a notice. 126 | * 127 | * @param mixed String/Array for the message(s) 128 | */ 129 | public static function notice($message) 130 | { 131 | self::set(Message::NOTICE, $message); 132 | } 133 | 134 | /** 135 | * Sets a success message. 136 | * 137 | * @param mixed String/Array for the message(s) 138 | */ 139 | public static function success($message) 140 | { 141 | self::set(Message::SUCCESS, $message); 142 | } 143 | 144 | /** 145 | * Sets a warning message. 146 | * 147 | * @param mixed String/Array for the message(s) 148 | */ 149 | public static function warn($message) 150 | { 151 | self::set(Message::WARN, $message); 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /config/userguide.php: -------------------------------------------------------------------------------- 1 | array 6 | ( 7 | 'message' => array 8 | ( 9 | 'enabled' => TRUE, 10 | 'name' => "Message", 11 | 'description' => "A flash messaging system for Kohana v3.0 and higher.", 12 | 'copyright' => '© 2010–2011 Dave Widmer', 13 | ) 14 | ) 15 | ); 16 | -------------------------------------------------------------------------------- /guide/message/index.md: -------------------------------------------------------------------------------- 1 | # Message 2 | 3 | A flash messaging system for Kohana v3.0 and higher. 4 | 5 | To use, download the source, extract and rename to message. Move that folder 6 | into your modules directory and activate in your bootstrap. 7 | 8 | ## Usage 9 | To set a flash message all it takes is the following 10 | 11 | Message::set($type, $message); 12 | 13 | | Name | Description | 14 | |---------|-----------------------------------------------------------| 15 | | type | The type of message that this is (error, success, etc...) | 16 | | message | A string or array of strings | 17 | 18 | ## Wrapper methods 19 | There are also methods that are wrappers for the different types of messages. 20 | 21 | Message::error($message) 22 | Message::success($message) 23 | Message::notice($message) 24 | Message::warn($message) 25 | 26 | When you need to get a message you can: 27 | 28 | echo Message::display(); or 29 | echo Message::render(); 30 | 31 | ### Custom Views 32 | 33 | You can also pass the name of a custom view into the `Message::display()` or 34 | `Message::render()` functions (e.g. `Message::display('message/custom')`) 35 | 36 | In your custom view you will get a variable `$message` that has properties of `$type` 37 | and `$message` described above under usage. 38 | 39 | 40 | ## Messages 41 | 42 | There are 4 constants you can use to set a message 43 | 44 | Message::ERROR = 'error' 45 | Message::NOTICE = 'notice' 46 | Message::SUCCESS = 'success' 47 | Message::WARN = 'warn' 48 | 49 | ## Style 50 | The message class produces the following code by default. 51 | 52 | 56 | 57 | To style, set #message and the classes for the constants .error, .success, .notice, .warn 58 | 59 | ----- 60 | 61 | ### Sample Usage 62 | 63 | I get the most mileage from this class when validating forms. Here is a quick example. 64 | 65 | $validation = new Validate($_POST); 66 | $validation->rule(.....) <-- Add rules 67 | 68 | if($validation->check()) 69 | { 70 | // Validation passed 71 | Message::success('Form Success!'); 72 | // OR -> Message::set(Message::SUCCESS, 'Form Success!'); 73 | } 74 | else 75 | { 76 | // Validation failed 77 | Message::error($validation->errors('form'); 78 | // OR -> Message::set(Message::ERROR, $validation->errors('form')); 79 | } -------------------------------------------------------------------------------- /guide/message/menu.md: -------------------------------------------------------------------------------- 1 | ## [Message]() -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Message 2 | 3 | A flash messaging system for Kohana v3.0 and higher. 4 | 5 | To use, download the source, extract and rename to message. Move that folder into your modules directory and activate in your bootstrap. 6 | 7 | ## Usage 8 | To set a flash message all it takes is the following 9 | 10 | Message::set( _type_, _message_ ); 11 | 12 | ## Wrapper methods 13 | There are also methods that are wrappers for the different types of messages 14 | Message::error(_message_) 15 | Message::success(_message_) 16 | Message::notice(_message_) 17 | Message::warn(_message_) 18 | 19 | _type_: Use a constant that can be found below 20 | _message_: A message string or array of message strings 21 | 22 | When you need to get a message you can: 23 | echo Message::display(); or 24 | echo Message::render(); 25 | 26 | ## Messages 27 | 28 | There are 4 constants you can use to set a message 29 | 30 | Message::ERROR = 'error' 31 | Message::NOTICE = 'notice' 32 | Message::SUCCESS = 'success' 33 | Message::WARN = 'warn' 34 | 35 | ## Style 36 | The message class produces the following code by default 37 | 41 | 42 | To style, set #message and the classes for the constants 43 | .error, .success, .notice, .warn 44 | 45 | ----- 46 | 47 | ### Sample Usage 48 | 49 | I get the most mileage from this class when validating forms. Here is a quick example. 50 | 51 | $validation = new Validate($_POST); 52 | $validation->rule(.....) <-- Add rules 53 | 54 | if( $validation->check() ) 55 | { 56 | // Validation passed 57 | Message::success('Form Success!'); 58 | // OR -> Message::set(Message::SUCCESS, 'Form Success!'); 59 | } 60 | else 61 | { 62 | // Validation failed 63 | Message::error($validation->errors('_form_'); 64 | // OR -> Message::set(Message::ERROR, $validation->errors('_form_')); 65 | } 66 | -------------------------------------------------------------------------------- /views/message/basic.php: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------