本文整理汇总了PHP中Cake\ORM\RulesChecker::addCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP RulesChecker::addCreate方法的具体用法?PHP RulesChecker::addCreate怎么用?PHP RulesChecker::addCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\RulesChecker
的用法示例。
在下文中一共展示了RulesChecker::addCreate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildRules
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn('character_id', 'characters'));
$rules->add($rules->existsIn('skill_id', 'skills'));
$rules->addCreate([$this, 'addRelations']);
$rules->addCreate([$this, 'disallowDeprecated']);
$rules->addCreate([$this, 'hasXPAvailable']);
return $rules;
}
示例2: buildRules
/**
* Application rules.
*
* @param \Cake\ORM\RulesChecker $rules The rule checker
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules)
{
// check max instances limit
$rules->addCreate(function ($instance, $options) {
$info = (array) $instance->info();
if (isset($info['maxInstances']) && $info['maxInstances'] > 0) {
if (!$instance->get('eav_attribute')) {
return false;
}
$count = $this->find()->select(['FieldInstances.id', 'FieldInstances.handler', 'EavAttribute.id', 'EavAttribute.table_alias'])->contain(['EavAttribute'])->where(['EavAttribute.table_alias' => $instance->get('eav_attribute')->get('table_alias'), 'FieldInstances.handler' => $instance->get('handler')])->count();
return $count <= intval($info['maxInstances']) - 1;
}
return true;
}, 'maxInstances', ['errorField' => 'label', 'message' => __d('field', 'No more instances of this field can be attached, limit reached.')]);
return $rules;
}
示例3: buildRules
/**
*
* @param RulesChecker $rules
*/
public function buildRules(RulesChecker $rules)
{
$rules->addCreate($rules->isUnique(['name']), 'uniqueName', ['message' => 'Już istnieje taka rola']);
return $rules;
}