You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert

128
126
129
-
4 Usage
130
-
----------------------------
127
+
## Usage
131
128
132
-
### 4.1 Main properties
129
+
### Main properties
133
130
134
-
The **name** of module: ```mfuploader```
131
+
The **name** of module: `mfuploader`
135
132
136
-
The **namespace** for used classes: ```Itstructure\MFUploader```.
133
+
The **namespace** for used classes: `Itstructure\MFUploader`.
137
134
138
-
The **alias** to access in to module root directory: ```@mfuploader```.
135
+
The **alias** to access in to module root directory: `@mfuploader`.
139
136
140
-
### 4.2 Application config
137
+
### Application config
141
138
142
139
Base application config must be like in example below:
143
140
@@ -200,18 +197,18 @@ use Itstructure\MFUploader\components\{
200
197
],
201
198
```
202
199
203
-
Here ```publicBaseUrl``` for example can be a project domain (```http://your-site-address.com```).
204
-
If we have ```url``` in ```mediafiles``` table ```\uploads\images\imagealbum\0d\3890\a947f268d6f9fd02d8a0d7e147da922c.jpg```, and we use **getViewUrl()** function from a ```mediafile``` model for local files,
205
-
then for example a result link to image for ```src``` attribute of ```<img>``` tag will be:
200
+
Here `publicBaseUrl` for example can be a project domain (`http://your-site-address.com`).
201
+
If we have `url` in `mediafiles` table `\uploads\images\imagealbum\0d\3890\a947f268d6f9fd02d8a0d7e147da922c.jpg`, and we use **getViewUrl()** function from a `mediafile` model for local files,
202
+
then for example a result link to image for `src` attribute of `<img>` tag will be:
**Note:** It is not necessary to configure two components: ```local-upload-component``` and ```s3-upload-component```.
210
-
You must configure minimum one component, according with the ```defaultStorageType```.
206
+
**Note:** It is not necessary to configure two components: `local-upload-component` and `s3-upload-component`.
207
+
You must configure minimum one component, according with the `defaultStorageType`.
211
208
212
-
### 4.3 File field for the view template
209
+
### File field for the view template
213
210
214
-
**File field** must be rendered by ```FileSetter``` widget.
211
+
**File field** must be rendered by `FileSetter` widget.
215
212
216
213
It is necessary to send an ID or URL of uploaded mediafile to you application controller and set in
217
214
model.
@@ -224,6 +221,7 @@ use Itstructure\MFUploader\widgets\FileSetter;
224
221
use Itstructure\MFUploader\Module as MFUModule;
225
222
use Itstructure\MFUploader\interfaces\UploadModelInterface;
226
223
```
224
+
227
225
```html
228
226
Container to display selected image.
229
227
<divclass="media">
@@ -235,6 +233,7 @@ Container to display selected image.
235
233
</div>
236
234
</div>
237
235
```
236
+
238
237
```php
239
238
echo FileSetter::widget([
240
239
'model' => $model,
@@ -254,32 +253,32 @@ echo FileSetter::widget([
254
253
]);
255
254
```
256
255
257
-
### 4.4 Configure upload components
256
+
### Configure upload components
258
257
259
-
#### 4.4.1 Base attributes in BaseUploadComponent
258
+
#### Base attributes in BaseUploadComponent
260
259
261
260
**Note:** BaseUploadComponent - the base class, which LocalUploadComponent and S3UploadComponent extend.
262
261
263
-
To understand the principles of configure the base attributes, see public attributes in ```components\BaseUploadComponent``` class.
264
-
But it may be difficult to configure ```thumbsConfig``` and ```thumbFilenameTemplate```.
265
-
Attribute ```thumbsConfig``` takes the values according with the next chain:
266
-
1. From the default config file ```config/thumbs-config.php``` in module **init()** function.
267
-
2. Can be rewrited by custom during module ```thumbsConfig``` attribute.
268
-
3. Previous config result inserted in to the ```LocalUploadComponent``` and ```S3UploadComponent``` module components.
269
-
4. Configuration ```thumbsConfig``` in module components can be rewrited by custom during component ```thumbsConfig``` attribute.
262
+
To understand the principles of configure the base attributes, see public attributes in `components\BaseUploadComponent` class.
263
+
But it may be difficult to configure `thumbsConfig` and `thumbFilenameTemplate`.
264
+
Attribute `thumbsConfig` takes the values according with the next chain:
265
+
1. From the default config file `config/thumbs-config.php` in module **init()** function.
266
+
2. Can be rewrited by custom during module `thumbsConfig` attribute.
267
+
3. Previous config result inserted in to the `LocalUploadComponent` and `S3UploadComponent` module components.
268
+
4. Configuration `thumbsConfig` in module components can be rewrited by custom during component `thumbsConfig` attribute.
270
269
271
-
#### 4.4.2 Attributes in LocalUploadComponent
270
+
#### Attributes in LocalUploadComponent
272
271
273
-
That is very simple. See public attributes in ```components\LocalUploadComponent``` class.
272
+
That is very simple. See public attributes in `components\LocalUploadComponent` class.
274
273
275
-
#### 4.4.3 Attributes in S3UploadComponent
274
+
#### Attributes in S3UploadComponent
276
275
277
-
See public attributes in ```components\S3UploadComponent``` class.
276
+
See public attributes in `components\S3UploadComponent` class.
278
277
But there are important attributes:
279
-
-```credentials```. Attribute to access in to Amazon web services account.
278
+
-`credentials`. Attribute to access in to Amazon web services account.
280
279
Can be: array, callable, and other. See https://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html.
281
-
-```s3DefaultBucket``` - bucket, which you use to upload files as default.
282
-
-```s3Buckets``` - buckets to upload files depending on the owner. Not required.
280
+
-`s3DefaultBucket` - bucket, which you use to upload files as default.
281
+
-`s3Buckets` - buckets to upload files depending on the owner. Not required.
283
282
284
283
config example:
285
284
```php
@@ -296,23 +295,24 @@ For more information of S3 configuration, see the next links:
296
295
- https://docs.aws.amazon.com/aws-sdk-php/v3/api
297
296
- https://github.com/aws/aws-sdk-php
298
297
299
-
### 4.5 Link entities with owners
298
+
### Link entities with owners
300
299
301
-
To link entities (mediafiles and albums) with owners (pages, articles, posts e.t.c...) there is the abstract class ```behaviors\Behavior```.
300
+
To link entities (mediafiles and albums) with owners (pages, articles, posts e.t.c...) there is the abstract class `behaviors\Behavior`.
302
301
303
-
You must use child classes: ```behaviors\BehaviorMediafile``` and ```behaviors\BehaviorAlbum```.
302
+
You must use child classes: `behaviors\BehaviorMediafile` and `behaviors\BehaviorAlbum`.
304
303
305
304
Explanation by example.
306
305
307
-
You have a ```catalog``` model which extends an ActiveRecord yii2 class.
306
+
You have a `catalog` model which extends an ActiveRecord yii2 class.
308
307
309
-
Use a ```behaviors\BehaviorMediafile``` and ```behaviors\BehaviorAlbum``` in **behaviors** of your ```catalog``` model to link mediafiles and albums with catalog after: **insert active record**, **update active record**, **delete active record**:
308
+
Use a `behaviors\BehaviorMediafile` and `behaviors\BehaviorAlbum` in **behaviors** of your `catalog` model to link mediafiles and albums with catalog after: **insert active record**, **update active record**, **delete active record**:
310
309
311
310
```php
312
311
use Itstructure\MFUploader\behaviors\{BehaviorMediafile, BehaviorAlbum};
313
312
use Itstructure\MFUploader\interfaces\UploadModelInterface;
314
313
use Itstructure\MFUploader\models\album\Album;
315
314
```
315
+
316
316
```php
317
317
public $thumbnail;
318
318
@@ -339,73 +339,62 @@ public function behaviors()
339
339
}
340
340
```
341
341
342
-
**Note:** This block should be used in conjunction with the ```FileSetter``` widget inside the view form template!
342
+
**Note:** This block should be used in conjunction with the `FileSetter` widget inside the view form template!
343
343
344
344
Here the following happens:
345
345
346
-
- If you use a "thumbnail" name of ```attribute``` param in FileSetter widget, the uploaded mediafile (thumbnail) will be linked with ```catalog``` after insert new catalog data to the data base.
347
-
- If you use an "imageAlbum" (by Album::ALBUM_TYPE_IMAGE) name of the ```name``` attribute of dropdown or checkbox html field, the last created image album will be linked with ```catalog``` after insert new catalog data to the data base.
346
+
- If you use a "thumbnail" name of `attribute` param in FileSetter widget, the uploaded mediafile (thumbnail) will be linked with `catalog` after insert new catalog data to the data base.
347
+
- If you use an "imageAlbum" (by Album::ALBUM_TYPE_IMAGE) name of the `name` attribute of dropdown or checkbox html field, the last created image album will be linked with `catalog` after insert new catalog data to the data base.
348
348
349
349
That works according with the next data base example structure:
350
350
351
-
```Table "mediafiles"``` - record with id=20 now inserted.
351
+
`Table "mediafiles"` - record with id=20 now inserted.
**Note:** If you set in ```FileSetter``` widget the attributes: ```owner```, ```ownerId```, ```ownerAttribute``` - linking entity with owner will be done automatically during ajax request in **uploadmanager**.
386
+
**Note:** If you set in `FileSetter` widget the attributes: `owner`, `ownerId`, `ownerAttribute` - linking entity with owner will be done automatically during ajax request in **uploadmanager**.
397
387
398
-
### 4.6 Integrated album controllers
388
+
### Integrated album controllers
399
389
400
-
There are already integrated album controllers in the namespace: ```Itstructure\MFUploader\controllers\album```.
390
+
There are already integrated album controllers in the namespace: `Itstructure\MFUploader\controllers\album`.
401
391
Controllers provide the work with the next types of albums: **imageAlbum**, **audioAlbum**, **videoAlbum**, **applicationAlbum**, **textAlbum**, **otherAlbum**.
402
392
403
393
For that controllers there are already the models and view templates.
404
394
405
395
To work with that, you must set just the routes in application configuration.
0 commit comments