<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
baha2odeh / yii2-easy-fileupload-behavior example snippets
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['images_files','image_file'],'file'], //@TODO add your rules here
];
}
public function behaviors()
{
return [
[
'class' => EasyFileUploadBehavior::className(),
'relations' => [
'images_files' => 'images', // images means your HasMany Relation Name
'image_file' => 'image', // image means your HasOne Relation Name
],
'uploadCallBack' => function($relationName,UploadedFile $file){
// do your magic here and return one model that you save the image on it
// if return is null file will skipped
$file->saveAs('upload-path/'.$file->name);
$image = new Image();
$image->filename = $file->name;
$image->save(false);
return $image;
}
]
];
}
//// demo only ////
/**
* @return \yii\db\ActiveQuery
*/
public function getImage()
{
return $this->hasOne(Image::className(), ['image_id' => 'image_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticleImages()
{
return $this->hasMany(ArticleImage::className(), ['article_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getImages()
{
return $this->hasMany(Image::className(), ['image_id' => 'image_id'])->via('articleImages');
}
//// demo only ////
$form = ActiveForm::begin();
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.