PHP Class yii\mongodb\file\ActiveRecord

To specify source file use the [[file]] attribute. It can be specified in one of the following ways: - string - full name of the file, which content should be stored in GridFS - \yii\web\UploadedFile - uploaded file instance, which content should be stored in GridFS For example: php $record = new ImageFile(); $record->file = '/path/to/some/file.jpg'; $record->save(); You can also specify file content via [[newFileContent]] attribute: php $record = new ImageFile(); $record->newFileContent = 'New file content'; $record->save(); Note: [[newFileContent]] always takes precedence over [[file]].
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\mongodb\ActiveRecord
ファイルを表示 Open project: yiisoft/yii2-mongodb Class Usage Examples

Public Methods

Method Description
attributes ( ) : array Returns the list of all attribute names of the model.
find ( ) : yii\mongodb\file\ActiveQuery
getCollection ( ) : Collection Return the Mongo GridFS collection instance for this AR class.
getFileContent ( ) : null | string Returns the associated file content.
getFileResource ( ) : resource This method returns a stream resource that can be used with all file functions in PHP, which deal with reading files. The contents of the file are pulled out of MongoDB on the fly, so that the whole file does not have to be loaded into memory first.
refreshFile ( ) : MongoGridFSFile | null Refreshes the [[file]] attribute from file collection, using current primary key.
writeFile ( string $filename ) : boolean Writes the the internal file content into the given filename.

Protected Methods

Method Description
extractFileName ( mixed $file ) : string Extracts filename from given raw file value.
insertInternal ( $attributes = null )
updateInternal ( $attributes = null )

Method Details

attributes() public method

This method could be overridden by child classes to define available attributes. Note: all attributes defined in base Active Record class should be always present in returned array. For example: php public function attributes() { return array_merge( parent::attributes(), ['tags', 'status'] ); }
public attributes ( ) : array
return array list of attribute names.

extractFileName() protected method

Extracts filename from given raw file value.
protected extractFileName ( mixed $file ) : string
$file mixed raw file value.
return string file name.

find() public static method

public static find ( ) : yii\mongodb\file\ActiveQuery
return yii\mongodb\file\ActiveQuery the newly created [[ActiveQuery]] instance.

getCollection() public static method

Return the Mongo GridFS collection instance for this AR class.
public static getCollection ( ) : Collection
return Collection collection instance.

getFileContent() public method

Returns the associated file content.
public getFileContent ( ) : null | string
return null | string file content.

getFileResource() public method

This method returns a stream resource that can be used with all file functions in PHP, which deal with reading files. The contents of the file are pulled out of MongoDB on the fly, so that the whole file does not have to be loaded into memory first.
public getFileResource ( ) : resource
return resource file stream resource.

insertInternal() protected method

See also: ActiveRecord::insert()
protected insertInternal ( $attributes = null )

refreshFile() public method

Refreshes the [[file]] attribute from file collection, using current primary key.
public refreshFile ( ) : MongoGridFSFile | null
return MongoGridFSFile | null refreshed file value.

updateInternal() protected method

See also: ActiveRecord::update()
protected updateInternal ( $attributes = null )

writeFile() public method

Writes the the internal file content into the given filename.
public writeFile ( string $filename ) : boolean
$filename string full filename to be written.
return boolean whether the operation was successful.