1
|
|
|
<?php |
2
|
|
|
namespace App\Model\Table; |
3
|
|
|
|
4
|
|
|
use Cake\ORM\Query; |
5
|
|
|
use Cake\ORM\Table; |
6
|
|
|
use Cake\Validation\Validator; |
7
|
|
|
|
8
|
|
|
class BlogAttachmentsTable extends Table |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Initialize method |
13
|
|
|
* |
14
|
|
|
* @param array $config The configuration for the Table. |
15
|
|
|
* |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
public function initialize(array $config) |
19
|
|
|
{ |
20
|
|
|
$this->table('blog_attachments'); |
|
|
|
|
21
|
|
|
$this->displayField('name'); |
|
|
|
|
22
|
|
|
$this->primaryKey('id'); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$this->addBehavior('Timestamp'); |
25
|
|
|
$this->addBehavior('Xety/Cake3Upload.Upload', [ |
26
|
|
|
'fields' => [ |
27
|
|
|
'url' => [ |
28
|
|
|
'path' => 'upload/blog/attachment/:md5', |
29
|
|
|
'overwrite' => true |
30
|
|
|
] |
31
|
|
|
] |
32
|
|
|
]); |
33
|
|
|
|
34
|
|
|
$this->belongsTo('BlogArticles', [ |
35
|
|
|
'foreignKey' => 'article_id' |
36
|
|
|
]); |
37
|
|
|
$this->belongsTo('Users', [ |
38
|
|
|
'foreignKey' => 'user_id' |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Default validation rules. |
44
|
|
|
* |
45
|
|
|
* @param \Cake\Validation\Validator $validator The Validator instance. |
46
|
|
|
* |
47
|
|
|
* @return \Cake\Validation\Validator |
48
|
|
|
*/ |
49
|
|
|
public function validationDefault(Validator $validator) |
50
|
|
|
{ |
51
|
|
|
$validator |
52
|
|
|
->notEmpty('article_id', __("You must set an article.")) |
53
|
|
|
->add('article_id', 'numeric', [ |
54
|
|
|
'rule' => 'numeric', |
55
|
|
|
'message' => __("The article must be numeric value.") |
56
|
|
|
]) |
57
|
|
|
->notEmpty('url_file', __("You must upload a file.")) |
58
|
|
|
->add('url_file', [ |
59
|
|
|
'mimeType' => [ |
60
|
|
|
'rule' => ['mimeType', ['application/octet-stream', 'application/zip']], |
61
|
|
|
'message' => __("The mimeType is not allowed.") |
62
|
|
|
], |
63
|
|
|
'fileExtension' => [ |
64
|
|
|
'rule' => ['extension', ['zip']], |
65
|
|
|
'message' => __("The extension allowed are {0}.", '.zip') |
66
|
|
|
], |
67
|
|
|
'fileSize' => [ |
68
|
|
|
'rule' => ['fileSize', '<', '13MB'], |
69
|
|
|
'message' => __("The file exceeded the max allowed size of {0}.", '13MB') |
70
|
|
|
] |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
return $validator; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.