Blame view

src/Model/Table/SousCategoriesTable.php 1.81 KB
6c4edfa3   Alexandre   First Commit LabI...
1
2
3
<?php
namespace App\Model\Table;

6c4edfa3   Alexandre   First Commit LabI...
4
5
6
7
8
9
10
11
12
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * SousCategories Model
 *
 * @property \Cake\ORM\Association\BelongsTo $Categories
 */
0e5846aa   Alexandre   Css bouton valide...
13
class SousCategoriesTable extends AppTable
6c4edfa3   Alexandre   First Commit LabI...
14
15
16
17
18
{

    /**
     * Initialize method
     *
63c3cb16   epallier   Nombreux petits b...
19
20
     * @param array $config
     *            The configuration for the Table.
6c4edfa3   Alexandre   First Commit LabI...
21
22
23
24
25
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);
63c3cb16   epallier   Nombreux petits b...
26
        
6c4edfa3   Alexandre   First Commit LabI...
27
28
29
        $this->table('sous_categories');
        $this->displayField('id');
        $this->primaryKey('id');
63c3cb16   epallier   Nombreux petits b...
30
        
6c4edfa3   Alexandre   First Commit LabI...
31
32
33
34
35
36
37
38
39
        $this->belongsTo('Categories', [
            'foreignKey' => 'categorie_id',
            'joinType' => 'INNER'
        ]);
    }

    /**
     * Default validation rules.
     *
63c3cb16   epallier   Nombreux petits b...
40
41
     * @param \Cake\Validation\Validator $validator
     *            Validator instance.
6c4edfa3   Alexandre   First Commit LabI...
42
43
44
45
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
63c3cb16   epallier   Nombreux petits b...
46
47
48
        $validator->integer('id')->allowEmpty('id', 'create');
        
        $validator->requirePresence('nom', 'create')
0e5846aa   Alexandre   Css bouton valide...
49
            ->notEmpty('nom')
63c3cb16   epallier   Nombreux petits b...
50
51
52
53
54
55
56
57
            ->add('nom', 'valid', [
            'rule' => [
                'check_string'
            ],
            'message' => 'Le champ doit ĂȘtre valide.',
            'provider' => 'table'
        ]);
        
6c4edfa3   Alexandre   First Commit LabI...
58
59
60
61
62
63
64
        return $validator;
    }

    /**
     * Returns a rules checker object that will be used for validating
     * application integrity.
     *
63c3cb16   epallier   Nombreux petits b...
65
66
     * @param \Cake\ORM\RulesChecker $rules
     *            The rules object to be modified.
6c4edfa3   Alexandre   First Commit LabI...
67
68
69
70
     * @return \Cake\ORM\RulesChecker
     */
    public function buildRules(RulesChecker $rules)
    {
63c3cb16   epallier   Nombreux petits b...
71
72
73
        $rules->add($rules->existsIn([
            'categorie_id'
        ], 'Categories'));
6c4edfa3   Alexandre   First Commit LabI...
74
75
76
        return $rules;
    }
}