浏览代码

Improve Behavior docs

Ayman_Alkom 10 年之前
父节点
当前提交
3a9848a4f8
共有 4 个文件被更改,包括 156 次插入70 次删除
  1. 16 13
      docs/Behavior/Jsonable.md
  2. 18 16
      docs/Behavior/Passwordable.md
  3. 13 11
      docs/Behavior/Reset.md
  4. 109 30
      docs/Behavior/Slugged.md

+ 16 - 13
docs/Behavior/Jsonable.md

@@ -5,19 +5,22 @@ A CakePHP behavior to automatically store nested data as JSON string and return
 - Additional sanitize functionality with "clean", "sort" and "unique
 
 ## Configs
-- 'fields' => array(), // Fields to convert
-- 'input' => 'array', // json, array, param, list (param/list only works with specific fields)
-- 'output' => 'array', // json, array, param, list (param/list only works with specific fields)
-- 'separator' => '|', // only for param or list
-- 'keyValueSeparator' => ':', // only for param
-- 'leftBound' => '{', // only for list
-- 'rightBound' => '}', // only for list
-- 'clean' => true, // only for param or list (autoclean values on insert)
-- 'sort' => false, // only for list
-- 'unique' => true, // only for list (autoclean values on insert),
-- 'map' => array(), // map on a different DB field
-- 'encodeParams' // params for json_encode
-- 'decodeParams' // params for json_decode
+| Key  | Default | Description |
+| ------------- | ------------- | ------------- |
+| fields  | array() | Array of the fields to be converted  |
+| input  | 'array'  | can be \[json, array, param or list\] (param/list only works with specific fields) |
+| output  | 'array'  | can be \[json, array, param or list\] (param/list only works with specific fields) |
+| separator  | '\|'  | only for param or list |
+| keyValueSeparator  | ':'  | only for param |
+| leftBound  | '{'  | only for list |
+| rightBound  | '}'  | only for list |
+| clean  | true | only for list (auto clean values on insert) |
+| sort  | false | only for list |
+| unique  | true | only for list |
+| map  | array()  | map on a different DB field |
+| encodeParams  |   | params for json_encode |
+| decodeParams  |   | params for json_decode |
+
 
 ## Usage
 Attach it to your models in `initialize()` like so:

+ 18 - 16
docs/Behavior/Passwordable.md

@@ -11,22 +11,24 @@ Also capable of:
 - Don't allow the same password it was before (allowSame => false)
 
 ## Configs
-- 'field' => 'password',
-- 'confirm' => true, // Set to false if in admin view and no confirmation (pwd_repeat) is required
-- 'require' => true, // If a password change is required (set to false for edit forms, leave it true for pure password update forms)
-- 'current' => false, // Enquire the current password for security purposes
-- 'formField' => 'pwd',
-- 'formFieldRepeat' => 'pwd_repeat',
-- 'formFieldCurrent' => 'pwd_current',
-- 'userModel' => null, // Defaults to Users
-- 'auth' => null, // Which component (defaults to AuthComponent),
-- 'authType' => 'Form', // Which type of authenticate (Form, Blowfish, ...)
-- 'passwordHasher' => 'Default', // If a custom pwd hasher is been used
-- 'allowSame' => true, // Don't allow the old password on change
-- 'minLength' => PWD_MIN_LENGTH,
-- 'maxLength' => PWD_MAX_LENGTH,
-- 'validator' => 'default',
-- 'customValidation' => null, // Custom validation rule(s) for the formField on top
+| Key  | Default | Description |
+| ------------- | ------------- | ------------- |
+| field             |   'password'          |   |
+| confirm           |   true                |    Set to false if in admin view and no confirmation (pwd_repeat) is required     |
+| require           |   true                |    If a password change is required (set to false for edit forms, leave it true for pure password update forms)|
+| current           |   false               |    Enquire the current password for security purposes     |
+| formField         |   'pwd'               |   |
+| formFieldRepeat   |   'pwd_repeat'        |   |
+| formFieldCurrent  |   'pwd_current'       |   |
+| userModel         |   null                |   Defaults to Users      |
+| auth              |   null                |   Which component (defaults to AuthComponent)    |
+| authType          |   'Form'              |   Which type of authenticate (Form, Blowfish, ...)|
+| passwordHasher    |   'Default'           |   If a custom pwd hasher is been used         |
+| allowSame         |   true                |   Don't allow the old password on change      |
+| minLength         |   PWD_MIN_LENGTH      |   |   
+| maxLength         |   PWD_MAX_LENGTH      |   |   
+| validator         |   'default'           |   |
+| customValidation  |   null                |    Custom validation rule(s) for the formField on top     |
 
 You can either pass those to the behavior at runtime, or globally via Configure and `app.php`:
 ```php

+ 13 - 11
docs/Behavior/Reset.md

@@ -6,14 +6,16 @@ A CakePHP behavior to automatically "reset" all records as batch process
 - Custom callbacks attachable
 
 ## Configs
-- 'limit' => 100 // batch of records per loop
-- 'timeout' => null // in seconds
-- 'fields' => array() // if not displayField
-- 'updateFields' => array() // if saved fields should be different from fields
-- 'validate' => true // trigger beforeValidate callback
-- 'updateTimestamp' => false // update modified/updated timestamp
-- 'scope' => array() // optional conditions
-- 'callback' => null
+| Key  | Default | Description |
+| ------------- | ------------- | ------------- |
+|   limit           |   100       |    batch of records per loop    |
+|   timeout         |   null      |    in seconds                   |
+|   fields          |   array()   |    if not displayField          |
+|   updateFields    |   array()   |    if saved fields should be different from fields  |
+|   validate        |   true      |    trigger beforeValidate callback            |
+|   updateTimestamp |   false     |    update modified/updated timestamp          |
+|   scope           |   array()   |    optional conditions         |
+|   callback        |   null      |    |
 
 ## Usage
 Attach it to your models in `initialize()` like so:
@@ -52,7 +54,7 @@ Note that in this case we also use a timeout to avoid getting a penalty by Googl
 
 ### Advanced example: Resetting composite cache field
 
-In this case we added a new cache field to our messages in order to make the search faster with >> 100000 records. The data was containing all the info we needed  in serialized format. We needed a callback here as there was some logic involved. So we simply made a shell containing both callback method and shell command:
+In this case we added a new cache field to our messages in order to make the search faster with >> 100000 records. The data was containing all the info we needed – in serialized format. We needed a callback here as there was some logic involved. So we simply made a shell containing both callback method and shell command:
 ```php
 $this->Message->addBehavior('Tools.Reset', array(
     'fields' => array('data'), 'updateFields' => array('guest_name'),
@@ -72,7 +74,7 @@ public static function prepMessage(array $row) {
     return $row;
 }
 ```
-See the test cases for more ways to use callbacks  including adjusting the updateFields list.
+See the test cases for more ways to use callbacks – including adjusting the updateFields list.
 
-So as you can see, everything that involves a complete “re-save” including triggering of important
+So as you can see, everything that involves a complete “re-save� including triggering of important
 callbacks (in model and behaviors) of all or most records can leverage this behavior in a DRY, quick and reusable way.

+ 109 - 30
docs/Behavior/Slugged.md

@@ -6,36 +6,115 @@ A CakePHP behavior to automatically create and store slugs.
 - Multibyte aware, umlauts etc will be properly replaced
 
 ## Configs
-- label:
-	set to the name of a field to use for the slug, an array of fields to use as slugs or leave as null to rely
-	on the format returned by find('list') to determine the string to use for slugs
-- field: The slug field name
-- overwriteField: The boolean field to trigger overwriting if "overwrite" is false
-- mode: has the following values
-	ascii - retuns an ascii slug generated using the core Inflector::slug() function
-	display - a dummy mode which returns a slug legal for display - removes illegal (not unprintable) characters
-	url - returns a slug appropriate to put in a URL
-	class - a dummy mode which returns a slug appropriate to put in a html class (there are no restrictions)
-	id - retuns a slug appropriate to use in a html id
-- separator: The separator to use
-- length:
- Set to 0 for no length. Will be auto-detected if possible via schema.
-- overwrite: has 2 values
-	false - once the slug has been saved, do not change it (use if you are doing lookups based on slugs)
-	true - if the label field values change, regenerate the slug (use if you are the slug is just window-dressing)
-- unique: has 2 values
-	false - will not enforce a unique slug, whatever the label is is direclty slugged without checking for duplicates
-	true - use if you are doing lookups based on slugs (see overwrite)
-- case: has the following values
-	null - don't change the case of the slug
-	low - force lower case. E.g. "this-is-the-slug"
-	up - force upper case E.g. "THIS-IS-THE-SLUG"
-	title - force title case. E.g. "This-Is-The-Slug"
-	camel - force CamelCase. E.g. "ThisIsTheSlug"
-- replace: custom replacements as array
-- on: beforeSave or beforeValidate
-- scope: certain conditions to use as scope
-- tidy: If cleanup should be run on slugging
+<table>
+    <tbody>
+        <tr>
+            <th>Key</th>
+            <th>Default</th>
+            <th>Description</th>
+        </tr>
+        <tr>
+            <td>label</td>
+            <td>null</td>
+            <td>
+                <ul>
+                    <li> set to the name of a field to use for the slug </li>
+                    <li> an array of fields to use as slugs </li>
+                    <li> or leave as null to rely on the format returned by find('list') to determine the string to use for slugs </li>
+                </ul>
+            </td>
+        </tr>
+        <tr>
+            <td>    field   </td>
+            <td>    </td>
+            <td>    The slug field name     </td>
+        </tr>
+        <tr>
+            <td>    overwriteField  </td>
+            <td>        </td>
+            <td>    The boolean field to trigger overwriting if "overwrite" is false     </td>
+        </tr>
+        <tr>
+            <td>    mode    </td>
+            <td>    </td>
+            <td>
+                <ul>
+                    <li> <b>ascii: </b> retuns an ascii slug generated using the core Inflector::slug() function </li>
+                    <li> <b>display: </b> a dummy mode which returns a slug legal for display - removes illegal (not unprintable) characters </li>
+                    <li> <b>url: </b> returns a slug appropriate to put in a URL </li>
+                    <li> <b>class: </b> a dummy mode which returns a slug appropriate to put in a html class (there are no restrictions) </li>
+                    <li> <b>id: </b> returns a slug appropriate to use in a html id </li>
+                </ul>
+            </td>
+        </tr>
+        <tr>
+            <td>    separator  </td>
+            <td>    </td>
+            <td>    The separator to use     </td>
+        </tr>
+        <tr>
+            <td>    length  </td>
+            <td>    </td>
+            <td>    Set to 0 for no length. Will be auto-detected if possible via schema.     </td>
+        </tr>
+        <tr>
+            <td>    overwrite    </td>
+            <td>    </td>
+            <td>
+                has the following values
+                <ul>
+                    <li> <b>false: </b> once the slug has been saved, do not change it (use if you are doing lookups based on slugs) </li>
+                    <li> <b>true: </b> if the label field values change, regenerate the slug (use if you are the slug is just window-dressing) </li>
+                </ul>
+            </td>
+        </tr>
+        <tr>
+            <td>    unique    </td>
+            <td>    </td>
+            <td>
+                has the following values
+                <ul>
+                    <li> <b>false: </b> will not enforce a unique slug, whatever the label is is direclty slugged without checking for duplicates </li>
+                    <li> <b>true: </b> use if you are doing lookups based on slugs (see overwrite) </li>
+                </ul>
+            </td>
+        </tr>
+        <tr>
+            <td>    case    </td>
+            <td>    </td>
+            <td>
+                has the following values
+                <ul>
+                    <li>    <b> null    </b>    don't change the case of the slug           </li>
+                    <li>    <b> low     </b>    force lower case. E.g. "this-is-the-slug"   </li>
+                    <li>    <b> up      </b>    force upper case E.g. "THIS-IS-THE-SLUG"    </li>
+                    <li>    <b> title   </b>    force title case. E.g. "This-Is-The-Slug"   </li>
+                    <li>    <b> camel   </b>    force CamelCase. E.g. "ThisIsTheSlug"       </li>
+                </ul>
+            </td>
+        </tr>
+        <tr>
+            <td>    replace  </td>
+            <td>    </td>
+            <td>    custom replacements as array.     </td>
+        </tr>
+        <tr>
+            <td>    on  </td>
+            <td>    </td>
+            <td>    beforeSave or beforeValidate.     </td>
+        </tr>
+        <tr>
+            <td>    scope  </td>
+            <td>    </td>
+            <td>    certain conditions to use as scope.     </td>
+        </tr>
+        <tr>
+            <td>    tidy  </td>
+            <td>    </td>
+            <td>    If cleanup should be run on slugging.     </td>
+        </tr>
+    </tbody>
+</table>
 
 ## Usage
 Attach it to your models in `initialize()` like so: