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


PHP Schema::rules方法代码示例

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


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

示例1: validate

 /**
  * Validate the model
  *
  * @return boolean
  * @author Justin Palmer
  **/
 public function validate()
 {
     //print '<pre>';
     $boolean = true;
     $errors = array();
     $last_prop_name = '';
     //Run validation before calling save.
     $props = $this->props->export();
     $rules = $this->schema->rules();
     //var_dump($props);
     //Loop through the set properties.
     foreach ($props as $name => $value) {
         if (empty($errors)) {
             $last_prop_name = $name;
         }
         if (!empty($errors) && $last_prop_name != $name) {
             $this->errors->set($this->alias() . '[' . $last_prop_name . ']', $errors);
             $last_prop_name = $name;
             $errors = array();
         }
         //if the value is null and it is not a required property then lets just
         //continue onto the next property, nothing to do here.
         if ($value == NULL && !in_array($name, $this->schema()->required)) {
             continue;
         }
         //If there are rules for the property let's go through them.
         if ($rules->isKey($name)) {
             //print $name . ':' . $value . '<br/><br/>';
             //Get the rules.
             $prop_rules = $rules->get($name);
             //var_dump($prop_rules);
             foreach ($prop_rules as $key => $rule) {
                 $rule->value = $value;
                 if (!$rule->run()) {
                     if ($boolean) {
                         $boolean = false;
                     }
                     //Add the error message to some sort of array. So that we can add it to a flash.
                     $errors[] = $rule->message;
                 }
             }
         }
     }
     if (!empty($errors)) {
         $this->errors->set($this->alias() . '[' . $name . ']', $errors);
     }
     if (!$this->errors()->isEmpty()) {
         $boolean = false;
     }
     return $boolean;
 }
开发者ID:ToddBudde,项目名称:phrails,代码行数:57,代码来源:Model.php

示例2: testConfigFunctions

 /**
  * Tests some config functions.
  */
 public function testConfigFunctions()
 {
     // Create new schema
     $schema = new Schema();
     // Check return types
     $this->assertEquals(true, is_array($schema->attributeLabels()));
     $this->assertEquals(true, is_array($schema->rules()));
     $this->assertEquals(true, is_array($schema->relations()));
 }
开发者ID:cebe,项目名称:chive,代码行数:12,代码来源:SchemaTest.php


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