Abstract Class yii\mongodb\file\ActiveRecord
Inheritance | yii\mongodb\file\ActiveRecord » yii\mongodb\ActiveRecord » yii\db\BaseActiveRecord |
---|---|
Available since version | 2.0 |
ActiveRecord is the base class for classes representing Mongo GridFS files in terms of objects.
To specify source file use the \yii\mongodb\file\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:
$record = new ImageFile();
$record->file = '/path/to/some/file.jpg';
$record->save();
You can also specify file content via \yii\mongodb\file\newFileContent attribute:
$record = new ImageFile();
$record->newFileContent = 'New file content';
$record->save();
Note: \yii\mongodb\file\newFileContent always takes precedence over \yii\mongodb\file\file.
Public Methods
Method | Description | Defined By |
---|---|---|
attributes() | Returns the list of all attribute names of the model. | yii\mongodb\file\ActiveRecord |
collectionName() | Declares the name of the Mongo collection associated with this AR class. | yii\mongodb\ActiveRecord |
delete() | Deletes the document corresponding to this active record from the collection. | yii\mongodb\ActiveRecord |
deleteAll() | Deletes documents in the collection using the provided conditions. | yii\mongodb\ActiveRecord |
equals() | Returns a value indicating whether the given active record is the same as the current one. | yii\mongodb\ActiveRecord |
find() | yii\mongodb\file\ActiveRecord | |
getCollection() | Return the Mongo GridFS collection instance for this AR class. | yii\mongodb\file\ActiveRecord |
getDb() | Returns the Mongo connection used by this AR class. | yii\mongodb\ActiveRecord |
getFileContent() | Returns the associated file content. | yii\mongodb\file\ActiveRecord |
getFileResource() | 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. | yii\mongodb\file\ActiveRecord |
insert() | Inserts a row into the associated Mongo collection using the attribute values of this record. | yii\mongodb\ActiveRecord |
primaryKey() | Returns the primary key name(s) for this AR class. | yii\mongodb\ActiveRecord |
refreshFile() | Refreshes the \yii\mongodb\file\file attribute from file collection, using current primary key. | yii\mongodb\file\ActiveRecord |
updateAll() | Updates all documents in the collection using the provided attribute values and conditions. | yii\mongodb\ActiveRecord |
updateAllCounters() | Updates all documents in the collection using the provided counter changes and conditions. | yii\mongodb\ActiveRecord |
writeFile() | Writes the the internal file content into the given filename. | yii\mongodb\file\ActiveRecord |
Protected Methods
Method | Description | Defined By |
---|---|---|
deleteInternal() | yii\mongodb\ActiveRecord | |
extractFileName() | Extracts filename from given raw file value. | yii\mongodb\file\ActiveRecord |
insertInternal() | yii\mongodb\file\ActiveRecord | |
updateInternal() | yii\mongodb\file\ActiveRecord |
Method Details
Returns the list of all attribute names of the model.
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:
public function attributes()
{
return array_merge(
parent::attributes(),
['tags', 'status']
);
}
public array attributes ( ) | ||
return | array | List of attribute names. |
---|
Extracts filename from given raw file value.
protected string extractFileName ( $file ) | ||
$file | mixed | Raw file value. |
return | string | File name. |
---|---|---|
throws | \yii\base\InvalidParamException | on invalid file value. |
public static yii\mongodb\file\ActiveQuery find ( ) | ||
return | yii\mongodb\file\ActiveQuery | The newly created yii\mongodb\file\ActiveQuery instance. |
---|
Return the Mongo GridFS collection instance for this AR class.
public static yii\mongodb\file\Collection getCollection ( ) | ||
return | yii\mongodb\file\Collection | Collection instance. |
---|
Returns the associated file content.
public null|string getFileContent ( ) | ||
return | null|string | File content. |
---|---|---|
throws | \yii\base\InvalidParamException | on invalid file attribute value. |
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 resource getFileResource ( ) | ||
return | resource | File stream resource. |
---|---|---|
throws | \yii\base\InvalidParamException | on invalid file attribute value. |
See also yii\mongodb\file\ActiveRecord::insert().
protected void insertInternal ( $attributes = null ) | ||
$attributes |
Refreshes the \yii\mongodb\file\file attribute from file collection, using current primary key.
public \MongoGridFSFile|null refreshFile ( ) | ||
return | \MongoGridFSFile|null | Refreshed file value. |
---|
See also yii\mongodb\file\ActiveRecord::update().
protected void updateInternal ( $attributes = null ) | ||
$attributes | ||
throws | \yii\db\StaleObjectException |
---|
Writes the the internal file content into the given filename.
public boolean writeFile ( $filename ) | ||
$filename | string | Full filename to be written. |
return | boolean | Whether the operation was successful. |
---|---|---|
throws | \yii\base\InvalidParamException | on invalid file attribute value. |