當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。