2017 © Pedro Peláez
 

yii2-extension yii2-ica-mediafile

Extension for attaching media files to models.

image

icalab/yii2-ica-mediafile

Extension for attaching media files to models.

  • Wednesday, April 6, 2016
  • by icalab
  • Repository
  • 3 Watchers
  • 0 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 9 % Grown

The README.md

yii2-ica-mediafile

Extension for attaching media files to models, (*1)

Installation

  1. Install the mediafile extension using composer:
composer require icalab/yii2-ica-mediafile
  1. Run the provided migration:
php yii migrate --migrationPath=@icalab/mediafile/migrations
  1. Create a directory mediafiles under the web directory and make it writable for the web server.

Usage

The relevant code files contain documentation at the top of the files. There is also the Voorbeeld model and the VoorbeeldController that you can use to see an example of how this module works., (*2)

In short:, (*3)

  1. Create your model.
  2. Attach the ModelWithMediafileBehavior behavior to your model.
  3. Create a join table named yourmodel_mediafile containing a column parentid and a column mediafileid.
  4. Attach the behavior ControllerWithMediafileBehavior to your controller. Supply the class name of your model as a parameter (modelClass).
  5. Create an action actionUnassign($id, $mediafile) in your controller and make it call the unassignMediafile($id, $mediafile) method that comes from the ControllerWithMediafileBehavior behavior.
  6. In your update method, handle uploading of files by adding code like the following:
            $model->newFile = UploadedFile::getInstance($model, 'newFile');
            if($model->validate() && (! $model->newFiles || $this->saveMediaFiles($model)))
            {
                $model->save();
                $this->redirect(['update', 'id' => $id]);
            }
  1. In your form view, show the output of the AttachMediafileWidget widget. Supply the model and the form as a parameter to this widget:
echo AttachMediafileWidget::widget(['model' => $model, 'form' => $form]);

Notes

  • Uploaded media files can be accessed from the web using the url mediafile/view?id=id_of_file
  • By default uploaded images are converted to PNG to avoid further loss of quality. This was a requirement for the project we built this module for. If you don't want this, pass an extra parameter FALSE to the saveMediafile method the model inherits from the ModelWithMediafileBehavior behavior.
  • The AttachMediafileWidget uses Kartik Visweswaran's excellent FileInput widget: https://github.com/kartik-v/yii2-widget-fileinput

The Versions

06/04 2016

dev-master

9999999-dev https://github.com/icalab/yii2-ica-mediafile

Extension for attaching media files to models.

  Sources   Download

The Requires

 

extension yii2 widget media detail

02/07 2015

dev-turnintoextension

dev-turnintoextension

Extension for attaching media files to models.

  Sources   Download