Authored by ziy

添加,$this->validate和文档

@@ -4,7 +4,7 @@ namespace Hood; @@ -4,7 +4,7 @@ namespace Hood;
4 use Yaf\Controller_Abstract; 4 use Yaf\Controller_Abstract;
5 use Hood\Helper\View as hoodView; 5 use Hood\Helper\View as hoodView;
6 use Yaf; 6 use Yaf;
7 - 7 +use Hood\Validator as hoodValidator;
8 class Action extends Controller_Abstract 8 class Action extends Controller_Abstract
9 { 9 {
10 private $_viewLink = array(); 10 private $_viewLink = array();
@@ -168,6 +168,6 @@ class Action extends Controller_Abstract @@ -168,6 +168,6 @@ class Action extends Controller_Abstract
168 */ 168 */
169 public function validate(array $data, array $rules, array $messagesAttribute = array()) 169 public function validate(array $data, array $rules, array $messagesAttribute = array())
170 { 170 {
171 - return Validator::make($data, $rules, $messagesAttribute); 171 + return hoodValidator::make($data, $rules, $messagesAttribute);
172 } 172 }
173 } 173 }
1 #Validator 1 #Validator
  2 +```php
  3 +$validator = Validator::make(
  4 + ['url_str' => 'http://www.baidu.com'],
  5 + ['url_str' => 'url']
  6 +);
  7 +
  8 +判断错误
  9 +$validator->fails();
  10 +
  11 +判断正确
  12 +$validator->passes();
  13 +
  14 +获取所有验证的第一个错误,可以指定验证字段的第一个错误
  15 +$validator->messages()->first([$key=null]);
  16 +
  17 +获取所有验证的错误
  18 +$validator->messages()->all();
  19 +
  20 +获取指定验证字段的所有错误
  21 +$validator->messages()->get($key);
  22 +
  23 +判断是否有错误信息,可以指定验证字段
  24 +$validator->messages()->has([$key]);
  25 +
  26 +设定自定义错误信息
  27 +$validator->messages()->customMessages(['key'=>'mes']);
  28 +
  29 +设定指定验证字段错误消息
  30 +$validator->messages()->add($key,$mes);
  31 +```
  32 +
2 ##active_url 33 ##active_url
3 ```php 34 ```php
4 Validator::make( 35 Validator::make(