euromark 11 年之前
父节点
当前提交
34a60c502a
共有 2 个文件被更改,包括 24 次插入16 次删除
  1. 4 2
      docs/Component/Flash.md
  2. 20 14
      src/Controller/Component/FlashComponent.php

+ 4 - 2
docs/Component/Flash.md

@@ -3,11 +3,11 @@
 An enhanced FlashComponent capable of
 An enhanced FlashComponent capable of
 - Stackable messages for each type
 - Stackable messages for each type
 - Persistent (across requests) and transient messages
 - Persistent (across requests) and transient messages
-- Inject it into the headers as `X-Ajax-Flashmessage` for REST/AJAX requests
+- Inject it into the headers, as `X-Flash` for example, for REST/AJAX requests
 
 
 ## Configs
 ## Configs
 - 'headerKey' => 'X-Flash', // Set to empty string to deactivate
 - 'headerKey' => 'X-Flash', // Set to empty string to deactivate
-- 'sessionLimit' => 99 // Max message limit for session to avoid session flooding (Configure doesn't need one)
+- 'sessionLimit' => 99 // Max message limit for Session to avoid session flooding (Configure uses 99 fixed)
 
 
 ## Usage
 ## Usage
 Attach it to your controllers in `initialize()` like so:
 Attach it to your controllers in `initialize()` like so:
@@ -39,5 +39,7 @@ $this->Flash->error('O o.');
 ```
 ```
 
 
 ## Notes
 ## Notes
+It will also work with the AuthComponent, which internally uses FlashComponent::set(). This method has been provides as core hook internally.
+
 You can use any type (success, warning, error, info, ...) of message, except the two reserved ones `message` and `set`.
 You can use any type (success, warning, error, info, ...) of message, except the two reserved ones `message` and `set`.
 At least if you plan on using the magic method invokation. But even if not, it would be good practice to not use those two.
 At least if you plan on using the magic method invokation. But even if not, it would be good practice to not use those two.

+ 20 - 14
src/Controller/Component/FlashComponent.php

@@ -11,7 +11,7 @@ use Cake\Utility\Inflector;
  * persistent and transient.
  * persistent and transient.
  *
  *
  * @author Mark Scherer
  * @author Mark Scherer
- * @copyright 2012 Mark Scherer
+ * @copyright 2014 Mark Scherer
  * @license MIT
  * @license MIT
  */
  */
 class FlashComponent extends Component {
 class FlashComponent extends Component {
@@ -20,10 +20,16 @@ class FlashComponent extends Component {
 	 * @var array
 	 * @var array
 	 */
 	 */
 	protected $_defaultConfig = [
 	protected $_defaultConfig = [
-		'headerKey' => 'X-Flash', // Set to empty string to deactivate
+		'headerKey' => 'X-Flash', // Set to empty string to deactivate AJAX response
 		'sessionLimit' => 99 // Max message limit for session (Configure doesn't need one)
 		'sessionLimit' => 99 // Max message limit for session (Configure doesn't need one)
 	];
 	];
 
 
+	/**
+	 * FlashComponent::beforeFilter()
+	 *
+	 * @param Event $event
+	 * @return void
+	 */
 	public function beforeFilter(Event $event) {
 	public function beforeFilter(Event $event) {
 		$this->Controller = $event->subject();
 		$this->Controller = $event->subject();
 	}
 	}
@@ -118,18 +124,18 @@ class FlashComponent extends Component {
 		Configure::write('FlashMessage', $old);
 		Configure::write('FlashMessage', $old);
 	}
 	}
 
 
-/**
- * Magic method for verbose flash methods based on element names.
- *
- * For example: $this->Flash->success('My message') would use the
- * success.ctp element under `App/Template/Element/Flash` for rendering the
- * flash message.
- *
- * @param string $name Element name to use.
- * @param array $args Parameters to pass when calling `FlashComponent::set()`.
- * @return void
- * @throws \Cake\Network\Exception\InternalErrorException If missing the flash message.
- */
+	/**
+	 * Magic method for verbose flash methods based on element names.
+	 *
+	 * For example: $this->Flash->success('My message') would use the
+	 * success.ctp element under `App/Template/Element/Flash` for rendering the
+	 * flash message.
+	 *
+	 * @param string $name Element name to use.
+	 * @param array $args Parameters to pass when calling `FlashComponent::message()` or `set()`.
+	 * @return void
+	 * @throws \Cake\Network\Exception\InternalErrorException If missing the flash message.
+	 */
 	public function __call($name, $args) {
 	public function __call($name, $args) {
 		$options = ['element' => Inflector::underscore($name)];
 		$options = ['element' => Inflector::underscore($name)];