|
| 1 | +<?php |
| 2 | +namespace CaptchaDemo\Model\Table; |
| 3 | + |
| 4 | +use Cake\ORM\Query; |
| 5 | +use Cake\ORM\RulesChecker; |
| 6 | +use Cake\ORM\Table; |
| 7 | +use Cake\Validation\Validator; |
| 8 | + |
| 9 | +/** |
| 10 | + * Demo Model |
| 11 | + * |
| 12 | + * @method \CaptchaDemo\Model\Entity\Demo get($primaryKey, $options = []) |
| 13 | + * @method \CaptchaDemo\Model\Entity\Demo newEntity($data = null, array $options = []) |
| 14 | + * @method \CaptchaDemo\Model\Entity\Demo[] newEntities(array $data, array $options = []) |
| 15 | + * @method \CaptchaDemo\Model\Entity\Demo|false save(\Cake\Datasource\EntityInterface $entity, $options = []) |
| 16 | + * @method \CaptchaDemo\Model\Entity\Demo saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = []) |
| 17 | + * @method \CaptchaDemo\Model\Entity\Demo patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
| 18 | + * @method \CaptchaDemo\Model\Entity\Demo[] patchEntities($entities, array $data, array $options = []) |
| 19 | + * @method \CaptchaDemo\Model\Entity\Demo findOrCreate($search, callable $callback = null, $options = []) |
| 20 | + */ |
| 21 | +class DemoTable extends Table |
| 22 | +{ |
| 23 | + /** |
| 24 | + * Initialize method |
| 25 | + * |
| 26 | + * @param array $config The configuration for the Table. |
| 27 | + * @return void |
| 28 | + */ |
| 29 | + public function initialize(array $config) |
| 30 | + { |
| 31 | + parent::initialize($config); |
| 32 | + |
| 33 | + $this->setTable('_inimist_captcha_demo'); |
| 34 | + $this->setDisplayField('name'); |
| 35 | + $this->setPrimaryKey('id'); |
| 36 | + |
| 37 | + $this->addBehavior('Captcha.Captcha', ['field'=>'Captcha', 'secret'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx']); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Default validation rules. |
| 42 | + * |
| 43 | + * @param \Cake\Validation\Validator $validator Validator instance. |
| 44 | + * @return \Cake\Validation\Validator |
| 45 | + */ |
| 46 | + public function validationDefault(Validator $validator) |
| 47 | + { |
| 48 | + $validator |
| 49 | + ->integer('id') |
| 50 | + ->allowEmptyString('id', null, 'create'); |
| 51 | + |
| 52 | + $validator |
| 53 | + ->scalar('name') |
| 54 | + ->maxLength('name', 100) |
| 55 | + ->requirePresence('name', 'create') |
| 56 | + ->notEmptyString('name'); |
| 57 | + |
| 58 | + $validator |
| 59 | + ->email('email') |
| 60 | + ->requirePresence('email', 'create') |
| 61 | + ->notEmptyString('email'); |
| 62 | + |
| 63 | + return $validator; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Returns a rules checker object that will be used for validating |
| 68 | + * application integrity. |
| 69 | + * |
| 70 | + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
| 71 | + * @return \Cake\ORM\RulesChecker |
| 72 | + */ |
| 73 | + public function buildRules(RulesChecker $rules) |
| 74 | + { |
| 75 | + $rules->add($rules->isUnique(['email'])); |
| 76 | + |
| 77 | + return $rules; |
| 78 | + } |
| 79 | +} |
0 commit comments