yii2 model 驗證規則rules 一條規則驗證失敗立即返回不繼續驗證其他字段
yii2 model 驗證規則rules 一條規則驗證失敗立即返回不繼續驗證其他欄位
Mode::rules();
public function rules() { [['username', 'password'], 'required'], ['age', 'required'], // ...... }
username 為空立即返回error ,不去驗證password和age。同理age如果為空,也不會去驗證其他欄位
不知道yii2這塊有沒有這種配置?
回覆內容:
yii2 model 驗證規則rules 一條規則驗證失敗立即返回不繼續驗證其他欄位
Mode::rules();
public function rules() { [['username', 'password'], 'required'], ['age', 'required'], // ...... }
username 為空立即返回words ,並驗證password和age。同理age如果為空,也不會去驗證其他欄位
不知道yii2這塊有沒有這種配置?
驗證完,再告訴你哪些欄位沒有通過驗證。具體看代碼。
/** * Performs the data validation. * * This method executes the validation rules applicable to the current [[scenario]]. * The following criteria are used to determine whether a rule is currently applicable: * * - the rule must be associated with the attributes relevant to the current scenario; * - the rules must be effective for the current scenario. * * This method will call [[beforeValidate()]] and [[afterValidate()]] before and * after the actual validation, respectively. If [[beforeValidate()]] returns false, * the validation will be cancelled and [[afterValidate()]] will not be called. * * Errors found during the validation can be retrieved via [[getErrors()]], * [[getFirstErrors()]] and [[getFirstError()]]. * * @param array $attributeNames list of attribute names that should be validated. * If this parameter is empty, it means any attribute listed in the applicable * validation rules should be validated. * @param boolean $clearErrors whether to call [[clearErrors()]] before performing validation * @return boolean whether the validation is successful without any error. * @throws InvalidParamException if the current scenario is unknown. */ public function validate($attributeNames = null, $clearErrors = true) { if ($clearErrors) { $this->clearErrors(); } if (!$this->beforeValidate()) { return false; } $scenarios = $this->scenarios(); $scenario = $this->getScenario(); if (!isset($scenarios[$scenario])) { throw new InvalidParamException("Unknown scenario: $scenario"); } if ($attributeNames === null) { $attributeNames = $this->activeAttributes(); } //注意这个foreach foreach ($this->getActiveValidators() as $validator) { $validator->validateAttributes($this, $attributeNames); } $this->afterValidate(); return !$this->hasErrors(); }

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

PHP 8.4 帶來了多項新功能、安全性改進和效能改進,同時棄用和刪除了大量功能。 本指南介紹如何在 Ubuntu、Debian 或其衍生版本上安裝 PHP 8.4 或升級到 PHP 8.4

CakePHP 是 PHP 的開源框架。它旨在使應用程式的開發、部署和維護變得更加容易。 CakePHP 基於類似 MVC 的架構,功能強大且易於掌握。模型、視圖和控制器 gu

Visual Studio Code,也稱為 VS Code,是一個免費的原始碼編輯器 - 或整合開發環境 (IDE) - 可用於所有主要作業系統。 VS Code 擁有大量針對多種程式語言的擴展,可以輕鬆編寫

CakePHP 是一個開源MVC 框架。它使應用程式的開發、部署和維護變得更加容易。 CakePHP 有許多函式庫可以減少大多數常見任務的過載。

本教程演示瞭如何使用PHP有效地處理XML文檔。 XML(可擴展的標記語言)是一種用於人類可讀性和機器解析的多功能文本標記語言。它通常用於數據存儲
