Trait DataFileModel
Trait helps to get attached to the model file data.
For 'attache one' relation returns data array with fields:
* (string) full_path
* (string) path
* (string) title
* (string) alt, (*1)
For 'attache many' relation returns array with files data., (*2)
Installation
Require this package in your composer.json and update composer., (*3)
"kharanenka/oc-data-file-model": "1.*"
Uses
class MyModel extends Model
{
use DataFileModel;
public $attachOne = ['preview_image' => 'System\Models\File'];
public $attachMany = ['images' => 'System\Models\File'];
}
$obModel = MyModel::first();
$arFileData = $obModel->getFileData('preview_image');
$arFileList = $obModel->getFileListData('images');
Result:, (*4)
$arFileData = [
'full_path' => '...',
'path' => '...',
'title' => '...',
'alt' => '...',
];
$arFileList = [
[
'full_path' => '...',
'path' => '...',
'title' => '...',
'alt' => '...',
],[
'full_path' => '...',
'path' => '...',
'title' => '...',
'alt' => '...',
],
];