<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                #### 驗證數據完整性(Validating Data Integrity) Phalcon\Mvc\Model provides several events to validate data and implement business rules. The special “validation” event allows us to call built-in validators over the record. Phalcon exposes a few built-in validators that can be used at this stage of validation. Phalcon\Mvc\Model 對于驗證數據和實現業務規則,提供了多個事件。特殊的“驗證”事件允許我們在記錄上調用內置的驗證器。在這個驗證階段,有一些內置的驗證器可以使用。 The following example shows how to use it: 下面的例子展示了如何使用它: ~~~ <?php namespace Store\Toys; use Phalcon\Mvc\Model; use Phalcon\Validation; use Phalcon\Validation\Validator\Uniqueness; use Phalcon\Validation\Validator\InclusionIn; class Robots extends Model { public function validation() { $validator = new Validation(); $validator->add( "type", new InclusionIn( [ "domain" => [ "Mechanical", "Virtual", ] ] ) ); $validator->add( "name", new Uniqueness( [ "message" => "The robot name must be unique", ] ) ); return $this->validate($validator); } } ~~~ The above example performs a validation using the built-in validator “InclusionIn”. It checks the value of the field “type” in a domain list. If the value is not included in the method then the validator will fail and return false. 上面的例子使用內置的驗證器“InclusionIn”來執行驗證。它檢查域列表中的字段“type”的值。如果該值沒有包含在該方法中,那么驗證器將失敗并返回false。 * * * * * > For more information on validators, see the Validation documentation. >要獲得更多關于驗證器的信息,請參閱驗證文檔。 * * * * * The idea of creating validators is make them reusable between several models. A validator can also be as simple as: 創建驗證器的想法使它們可以在多個模型之間進行重用。驗證器也可以這么簡單: ~~~ <?php namespace Store\Toys; use Phalcon\Mvc\Model; use Phalcon\Mvc\Model\Message; class Robots extends Model { public function validation() { if ($this->type === "Old") { $message = new Message( "Sorry, old robots are not allowed anymore", "type", "MyType" ); $this->appendMessage($message); return false; } return true; } } ~~~ 驗證信息(Validation Messages) Phalcon\Mvc\Model has a messaging subsystem that provides a flexible way to output or store the validation messages generated during the insert/update processes. Phalcon\Mvc\Model 有一個消息子系統,它提供了一種靈活的方式來輸出或存儲在插入/更新過程中生成的驗證消息。 Each message is an instance of Phalcon\Mvc\Model\Message and the set of messages generated can be retrieved with the `getMessages()` method. Each message provides extended information like the field name that generated the message or the message type: 每個消息都是一個關于 Phalcon\Mvc\Model\Message 的實例,生成的消息集可以用getMessages()來檢索的方法。每個消息都提供了擴展信息,比如生成消息或消息類型的字段名: ~~~ <?php if ($robot->save() === false) { $messages = $robot->getMessages(); foreach ($messages as $message) { echo "Message: ", $message->getMessage(); echo "Field: ", $message->getField(); echo "Type: ", $message->getType(); } } ~~~ Phalcon\Mvc\Model can generate the following types of validation messages: 可以生成以下類型的驗證消息: | Type 類型 | Description 描述 | | --- | --- | | PresenceOf | Generated when a field with a non-null attribute on the database is trying to insert/update a null value 當數據庫中具有非null屬性的字段試圖插入/更新null值時生成| | ConstraintViolation | Generated when a field part of a virtual foreign key is trying to insert/update a value that doesn’t exist in the referenced model 當一個虛擬外鍵的字段部分試圖插入/更新引用模型中不存在的值時生成 | | InvalidValue | Generated when a validator failed because of an invalid value 由于無效值而導致驗證器失敗 | | InvalidCreateAttempt | Produced when a record is attempted to be created but it already exists 當一個記錄試圖被創建時產生,但它已經存在 | | InvalidUpdateAttempt | Produced when a record is attempted to be updated but it doesn’t exist | The `getMessages()` method can be overridden in a model to replace/translate the default messages generated automatically by the ORM: `getMessages()` 可以在模型中覆蓋方法來替換/轉換由ORM自動生成的默認消息: ~~~ <?php namespace Store\Toys; use Phalcon\Mvc\Model; class Robots extends Model { public function getMessages() { $messages = []; foreach (parent::getMessages() as $message) { switch ($message->getType()) { case "InvalidCreateAttempt": $messages[] = "The record cannot be created because it already exists"; break; case "InvalidUpdateAttempt": $messages[] = "The record cannot be updated because it doesn't exist"; break; case "PresenceOf": $messages[] = "The field " . $message->getField() . " is mandatory"; break; } } return $messages; } } ~~~ #### 驗證失敗事件(Validation Failed Events) Another type of events are available when the data validation process finds any inconsistency: 當數據驗證過程發現任何不一致時,可以使用另一種類型的事件。 | Operation 操作 | Name 名字 | Explanation 解釋 | | --- | --- | --- | | Insert or Update | notSaved | Triggered when the INSERT or UPDATE operation fails for any reason 當插入或更新操作因任何原因失敗時觸發 | | Insert, Delete or Update | onValidationFails | Triggered when any data manipulation operation fails 當任何數據操作操作失敗時觸發 |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看