2017 © Pedro Peláez
 

yii2-extension yii2-document

Yii2 model for storing documents

image

sateler/yii2-document

Yii2 model for storing documents

  • Friday, July 14, 2017
  • by fsateler
  • Repository
  • 2 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

Yii2 plugin for a document model

Yii2-document stores documents in your local database or any filesystem supported by Flysystem., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist sateler/yii2-document "^1.1"

or add, (*4)

"sateler/yii2-document": "^1.1"

to the require section of your composer.json file., (*5)

Once the extension is installed, add namespace to console config:, (*6)

return [
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationNamespaces' => [
                'sateler\document\migrations',
            ],
        ],
    ],
];

And controller to web config:, (*7)

return [
    'controllerMap' => [
        'documents' => [
            'class' => 'sateler\document\controllers\DocumentController',
        ]
    ],
];

Configuration

'documentManager' => [
    'class' => \sateler\document\DocumentManager::class,
    // Define default filesystem, of none given sql storage is used
    'defaultFilesystemId' => 'awsS3',
    'filesystems' => [
        // A flysystem filesystem config
        'awsS3' => [
            'class' => AwsS3Filesystem::class,
            'bucket' => 'bucket-name',
            'region' => 'us-east-1',
            'prefix' => 'path',
            'key' => 'key',
            'secret' => 'secret',
        ],
    ],
],

Usage

Once installed, you can now use sateler\document\Document in your relations, and redirect to ['documents/view', 'id' => $docId] to view or download., (*8)

Create a document and save it:, (*9)

$doc = new Document();
$doc->name = 'filename';
$doc->mime_type = 'mime/type';
$doc->contents = file_get_contents('/path/to/file');
$doc->save();

Get a document and send it:, (*10)

$doc = Document::findOne($id)
$res = Yii::$app->response;
$res->format = Response::FORMAT_RAW;
$res->setDownloadHeaders($doc->name, $doc->mime_type, true);
$res->data = $doc->contents;
$res->send();

The Versions

14/07 2017

dev-master

9999999-dev

Yii2 model for storing documents

  Sources   Download

MIT

The Requires

 

by Felipe Sateler

extension yii2 document

14/07 2017

1.0.1

1.0.1.0

Yii2 model for storing documents

  Sources   Download

MIT

The Requires

 

by Felipe Sateler

extension yii2 document

14/07 2017

1.0

1.0.0.0

Yii2 model for storing documents

  Sources   Download

MIT

The Requires

 

by Felipe Sateler

extension yii2 document