当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation::setLabels方法代码示例

本文整理汇总了PHP中Phalcon\Validation::setLabels方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::setLabels方法的具体用法?PHP Validation::setLabels怎么用?PHP Validation::setLabels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Validation的用法示例。


在下文中一共展示了Validation::setLabels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testValidationSetLabels

 public function testValidationSetLabels()
 {
     $this->specify("setLabels() doesn't work as expected", function () {
         $validation = new Validation();
         $validation->add('email', new Validation\Validator\PresenceOf(array('message' => 'The :field is required')));
         $validation->add('email', new Validation\Validator\Email(array('message' => 'The :field must be email', 'label' => 'E-mail')));
         $validation->add('firstname', new Validation\Validator\PresenceOf(array('message' => 'The :field is required')));
         $validation->add('firstname', new Validation\Validator\StringLength(array('min' => 4, 'messageMinimum' => 'The :field is too short')));
         $validation->setLabels(array('firstname' => 'First name'));
         $messages = $validation->validate(['email' => '', 'firstname' => '']);
         $expectedMessages = Group::__set_state(array('_messages' => array(0 => Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The email is required', '_field' => 'email', '_code' => '0')), 1 => Message::__set_state(array('_type' => 'Email', '_message' => 'The E-mail must be email', '_field' => 'email', '_code' => '0')), 2 => Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The First name is required', '_field' => 'firstname', '_code' => '0')), 3 => Message::__set_state(array('_type' => 'TooShort', '_message' => 'The First name is too short', '_field' => 'firstname', '_code' => '0')))));
         expect($messages)->equals($expectedMessages);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:14,代码来源:ValidationTest.php


注:本文中的Phalcon\Validation::setLabels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。