PHP code example of mix8872 / yii2-files

1. Go to this page and download the library: Download mix8872/yii2-files library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mix8872 / yii2-files example snippets


'modules' => [
    'files' => [
        'class' => 'mix8872\yiiFiles\Module',
        'parameters' => [ // general module parameters
            'sizes' => [ // if imgProcessDriver is GD supports only jpeg, png and gif
                'galleryMiddle' => ['width' => '880', 'height' => '587', 'model' => ['common\modules\imageslider\models\ImageSlider']],
                'galleryPreview' => ['width' => '120', 'height' => '60', 'model' => ['common\modules\imageslider\models\ImageSlider']]
            ],
            'sizesNameBy' => 'template', // or 'key', optional, default 'size'
            'sizesNameTemplate' => '_resize_%k-%s', //optional, if sizesNameBy set to 'template'
            'imgProcessDriver' => 'gd', //or 'imagick', optional, default 'gd',
            'filesNameBy' => 'translit', // optional, by default naming is random string
            'savePath' => '/uploads/attachments/', // optional, default save path is '/uploads/attachments/'
        ],
        'attributes' => [ // general attributes configuration, optional
            'preview' => [
                'filetypes' => ['image/*'],
                'resize' => ['width' => '1024', 'height' => '768'], //optional, if imgProcessDriver is GD supports only jpeg, png and gif
            ],
            'images' => [
                'multiple' => true,
                'filetypes' => ['image/*'],
            ]
        ]
    ],
	// ... other modules definition
],

public function behaviors()
    {
        return [
            'files' => [
                'class' => \mix8872\yiiFiles\behaviors\FileAttachBehavior::class,
                'attributes' => [
                    'images' => [
                        'multiple' => true, // optional, default false. allow multiple loading
                        'filetypes' => ['image/*'], // array of mime types of allowed files
                        'resize' => ['width' => '1024', 'height' => '768'], //optional, for images only
                    ],
                    'videos' => [

                    ]
                ],
            ],
            // ... other behaviors
        ];
    }

public function behaviors()
    {
        return [
            'files' => [
                'class' => \mix8872\yiiFiles\behaviors\FileAttachBehavior::class,
                ...
            ],
            // ... other behaviors
        ];
    }

public function behaviors()
    {
        return [
            'files' => [
                'class' => \mix8872\yiiFiles\behaviors\FileAttachBehavior::class,
                'attributes' => [ ... ],
                'indexBy' => 'code', // by default - id
                ...
            ],
            // ... other behaviors
        ];
    }

use mix8872\yiiFiles\widgets\FilesWidget;


$model->attachByUrl(string $tag, string $url);

$files = $model->getFiles('property'); //array of file objects

// public function getFiles(string $property, bool $single, bool $asQuery)

$files = $model->property;

php composer.phar 

'modules' => [
        ...
        
        'files' => [
            'as access' => [
                'class' => \yii\filters\AccessControl::class,
                'rules' => [
                    [
                        'allow' => false,
                    ],
                ],
            ],
        ],
    ],

'modules' => [
        ...
        
        'files' => [
            'as access' => [
				'class' => 'yii\filters\AccessControl',
				'rules' => [
					[
						'controllers' => ['files/default'],
						'allow' => true,
						'roles' => ['admin']
					],
				]
			],
        ],
    ],