本文整理汇总了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;
}
示例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()));
}