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
Afficher le fichier Open project: yiisoft/yii2-mongodb Class Usage Examples

Méthodes publiques

Méthode 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.

Méthodes protégées

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

Method Details

attributes() public méthode

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
Résultat array list of attribute names.

extractFileName() protected méthode

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

find() public static méthode

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

getCollection() public static méthode

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

getFileContent() public méthode

Returns the associated file content.
public getFileContent ( ) : null | string
Résultat null | string file content.

getFileResource() public méthode

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
Résultat resource file stream resource.

insertInternal() protected méthode

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

refreshFile() public méthode

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

updateInternal() protected méthode

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

writeFile() public méthode

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