PHP Класс mdm\upload\UploadBehavior

Usage at [[\yii\base\Model::behaviors()]] add the following code ~~~ return [ ... [ 'class' => 'mdm\upload\UploadBehavior', 'uploadPath' => '@common/upload', // default to '@runtime/upload' 'attribute' => 'file', // attribute use to receive from FileField 'savedAttribute' => 'file_id', // attribute use to receive id of file ], ]; ~~~
С версии: 1.0
Автор: Misbahul D Munir ([email protected])
Наследование: extends yii\base\Behavior
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$attribute the attribute that will receive the uploaded file
$autoDelete when true then related file will be deleted on event 'beforeDelete'
$autoSave when true saveUploadedFile() will be called on event 'beforeSave'
$deleteOldFile boolean
$directoryLevel the level of sub-directories to store uploaded files. Defaults to 1. If the system has huge number of uploaded files (e.g. one million), you may use a bigger value (usually no bigger than 3). Using sub-directories is mainly to ensure the file system is not over burdened with a single directory having too many files.
$saveCallback Closure | string
$savedAttribute the attribute that will receive the file id
$uploadPath the directory to store uploaded files. You may use path alias here. If not set, it will use the "upload" subdirectory under the application runtime path.

Открытые методы

Метод Описание
__get ( $name )
__set ( $name, $value )
beforeDelete ( ModelEvent $event ) Event handler for beforeDelete
beforeSave ( ModelEvent $event ) Event handler for beforeSave
canGetProperty ( $name, $checkVars = true )
canSetProperty ( $name, $checkVars = true )
events ( )
getSavedFile ( ) : FileModel Get saved file
init ( )
saveUploadedFile ( boolean $deleteOldFile = null ) : boolean | null Save uploaded file into [[$uploadPath]]

Описание методов

__get() публичный метод

public __get ( $name )

__set() публичный метод

public __set ( $name, $value )

beforeDelete() публичный метод

Event handler for beforeDelete
public beforeDelete ( ModelEvent $event )
$event yii\base\ModelEvent

beforeSave() публичный метод

Event handler for beforeSave
public beforeSave ( ModelEvent $event )
$event yii\base\ModelEvent

canGetProperty() публичный метод

public canGetProperty ( $name, $checkVars = true )

canSetProperty() публичный метод

public canSetProperty ( $name, $checkVars = true )

events() публичный метод

public events ( )

getSavedFile() публичный метод

Get saved file
public getSavedFile ( ) : FileModel
Результат FileModel

init() публичный метод

public init ( )

saveUploadedFile() публичный метод

Save uploaded file into [[$uploadPath]]
public saveUploadedFile ( boolean $deleteOldFile = null ) : boolean | null
$deleteOldFile boolean If true and file exists, file will be deleted.
Результат boolean | null if success return true, fault return false. Return null mean no uploaded file.

Описание свойств

$attribute публичное свойство

the attribute that will receive the uploaded file
public $attribute

$autoDelete публичное свойство

when true then related file will be deleted on event 'beforeDelete'
public $autoDelete

$autoSave публичное свойство

when true saveUploadedFile() will be called on event 'beforeSave'
public $autoSave

$deleteOldFile публичное свойство

public bool $deleteOldFile
Результат boolean

$directoryLevel публичное свойство

the level of sub-directories to store uploaded files. Defaults to 1. If the system has huge number of uploaded files (e.g. one million), you may use a bigger value (usually no bigger than 3). Using sub-directories is mainly to ensure the file system is not over burdened with a single directory having too many files.
public $directoryLevel

$saveCallback публичное свойство

public Closure|string $saveCallback
Результат Closure | string

$savedAttribute публичное свойство

the attribute that will receive the file id
public $savedAttribute

$uploadPath публичное свойство

the directory to store uploaded files. You may use path alias here. If not set, it will use the "upload" subdirectory under the application runtime path.
public $uploadPath