├── .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 |