CakePHP - Walidacja
Często podczas tworzenia witryn internetowych musimy zweryfikować pewne rzeczy przed dalszym przetwarzaniem danych. CakePHP dostarcza pakiet walidacyjny do tworzenia walidatorów, które mogą z łatwością walidować dane.
Metody walidacji
CakePHP zapewnia różne metody walidacji w klasie walidacji. Poniżej wymieniono niektóre z najpopularniejszych z nich.
| Składnia | Add (string $ field, array | string $ name, array | Cake \ Validation \ ValidationRule $ rule []) |
|---|---|
| Parametry |
|
| Zwroty | $ this |
| Opis | Dodaje nową regułę do zestawu reguł pola. Jeśli drugim argumentem jest tablica, to lista reguł dla pola zostanie zastąpiona drugim argumentem, a trzeci argument zostanie zignorowany. |
| Składnia | allowEmpty (string $ field , boolean | string | callable $ when true, string | null $ message null) |
|---|---|
| Parametry |
|
| Zwroty | $ this |
| Opis | Pozwala, aby pole było puste. |
| Składnia | alphanumeric (string $ field , string | null $ message null, string | callable | null $ when null) |
| Parametry |
|
| Zwroty | $ this |
| Opis | Dodaj regułę alfanumeryczną do pola. |
| Składnia | CreditCard (string $ field , string $ type 'all', string | null $ message null, string | callable | null $ when null) |
|---|---|
| Parametry |
|
| Zwroty | $ this |
| Opis | Dodaj regułę karty kredytowej do pola. |
| Składnia | Email (string $ field, boolean $ checkMX false, string | null $ message null, string | callable | null, $ when null) |
|---|---|
| Parametry |
|
| Zwroty | $ this |
| Opis | Dodaj regułę sprawdzania poprawności adresu e-mail do pola. |
| Składnia | maxLength (string $ field , integer $ max , string | null $ message null, string | callable | null $ gdy null) |
|---|---|
| Parametry |
|
| Zwroty | $ this |
| Opis | Dodaj regułę sprawdzania poprawności długości łańcucha do pola. |
| Składnia | minLength (string $ field , integer $ min , string | null $ message null, string | callable | null $ gdy null) |
|---|---|
| Parametry |
|
| Zwroty | $ this |
| Opis | Dodaj regułę sprawdzania poprawności długości łańcucha do pola. |
| Składnia | notBlank (string $ field , string | null $ message null, string | callable | null $ kiedy null) |
|---|---|
| Parametry |
|
| Zwroty | $ this |
| Opis | Dodaj regułę notBlank do pola. |