Commit bace91ee420f120d6ce895e89540af15bdff00e4

Authored by Karnovsky A
1 parent 22827c55

-

backend/controllers/ArticlesController.php
@@ -9,6 +9,8 @@ use yii\web\Controller; @@ -9,6 +9,8 @@ use yii\web\Controller;
9 use yii\web\NotFoundHttpException; 9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter; 10 use yii\filters\VerbFilter;
11 use developeruz\db_rbac\behaviors\AccessBehavior; 11 use developeruz\db_rbac\behaviors\AccessBehavior;
  12 +use yii\web\UploadedFile;
  13 +
12 /** 14 /**
13 * ArticlesController implements the CRUD actions for Articles model. 15 * ArticlesController implements the CRUD actions for Articles model.
14 */ 16 */
@@ -77,7 +79,16 @@ class ArticlesController extends Controller @@ -77,7 +79,16 @@ class ArticlesController extends Controller
77 { 79 {
78 $model = new Articles(); 80 $model = new Articles();
79 81
80 - if ($model->load(Yii::$app->request->post()) && $model->save()) { 82 + if ($model->load(Yii::$app->request->post())) {
  83 +
  84 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  85 + $model->image = $image->name;
  86 + }
  87 +
  88 + if ($model->save() && $image) {
  89 + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name));
  90 + }
  91 +
81 return $this->redirect(['view', 'id' => $model->id]); 92 return $this->redirect(['view', 'id' => $model->id]);
82 } else { 93 } else {
83 return $this->render('create', [ 94 return $this->render('create', [
@@ -96,7 +107,16 @@ class ArticlesController extends Controller @@ -96,7 +107,16 @@ class ArticlesController extends Controller
96 { 107 {
97 $model = $this->findModel($id); 108 $model = $this->findModel($id);
98 109
99 - if ($model->load(Yii::$app->request->post()) && $model->save()) { 110 + if ($model->load(Yii::$app->request->post())) {
  111 +
  112 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  113 + $model->image = $image->name;
  114 + }
  115 +
  116 + if ($model->save() && $image) {
  117 + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name));
  118 + }
  119 +
100 return $this->redirect(['view', 'id' => $model->id]); 120 return $this->redirect(['view', 'id' => $model->id]);
101 } else { 121 } else {
102 return $this->render('update', [ 122 return $this->render('update', [
backend/controllers/BlogController.php
@@ -79,10 +79,18 @@ class BlogController extends Controller @@ -79,10 +79,18 @@ class BlogController extends Controller
79 { 79 {
80 $model = new Blog(); 80 $model = new Blog();
81 81
82 - if ($model->load(Yii::$app->request->post()) && $model->save()) { 82 + if ($model->load(Yii::$app->request->post())) {
83 83
84 Fields::saveFieldData(Yii::$app->request->post('Fields'), $model->blog_id, Blog::className(), 'ru'); 84 Fields::saveFieldData(Yii::$app->request->post('Fields'), $model->blog_id, Blog::className(), 'ru');
85 85
  86 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  87 + $model->cover = $image->name;
  88 + }
  89 +
  90 + if ($model->save() && $image) {
  91 + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name));
  92 + }
  93 +
86 return $this->redirect(['view', 'id' => $model->blog_id]); 94 return $this->redirect(['view', 'id' => $model->blog_id]);
87 } else { 95 } else {
88 return $this->render('create', [ 96 return $this->render('create', [
@@ -101,8 +109,18 @@ class BlogController extends Controller @@ -101,8 +109,18 @@ class BlogController extends Controller
101 { 109 {
102 $model = $this->findModel($id); 110 $model = $this->findModel($id);
103 111
104 - if ($model->load(Yii::$app->request->post()) && $model->save()) { 112 + if ($model->load(Yii::$app->request->post())) {
  113 +
105 Fields::saveFieldData(Yii::$app->request->post('Fields'), $model->blog_id, Blog::className(), 'ru'); 114 Fields::saveFieldData(Yii::$app->request->post('Fields'), $model->blog_id, Blog::className(), 'ru');
  115 +
  116 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  117 + $model->cover = $image->name;
  118 + }
  119 +
  120 + if ($model->save() && $image) {
  121 + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name));
  122 + }
  123 +
106 return $this->redirect(['view', 'id' => $model->blog_id]); 124 return $this->redirect(['view', 'id' => $model->blog_id]);
107 } else { 125 } else {
108 return $this->render('update', [ 126 return $this->render('update', [
backend/controllers/BrandController.php
@@ -9,6 +9,8 @@ use yii\web\Controller; @@ -9,6 +9,8 @@ use yii\web\Controller;
9 use yii\web\NotFoundHttpException; 9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter; 10 use yii\filters\VerbFilter;
11 use yii\filters\AccessControl; 11 use yii\filters\AccessControl;
  12 +use yii\web\UploadedFile;
  13 +
12 /** 14 /**
13 * BrandController implements the CRUD actions for Brand model. 15 * BrandController implements the CRUD actions for Brand model.
14 */ 16 */
@@ -78,8 +80,15 @@ class BrandController extends Controller @@ -78,8 +80,15 @@ class BrandController extends Controller
78 public function actionCreate() 80 public function actionCreate()
79 { 81 {
80 $model = new Brand(); 82 $model = new Brand();
81 - if ($model->load(Yii::$app->request->post()) && $model->save()) {  
82 - exit; 83 + if ($model->load(Yii::$app->request->post())) {
  84 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  85 + $model->image = $image->name;
  86 + }
  87 +
  88 + if ($model->save() && $image) {
  89 + $image->saveAs(Yii::getAlias('@imagesDir/brands/' . $image->name));
  90 + }
  91 +
83 return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); 92 return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams));
84 } else { 93 } else {
85 return $this->render('create', [ 94 return $this->render('create', [
@@ -99,13 +108,15 @@ class BrandController extends Controller @@ -99,13 +108,15 @@ class BrandController extends Controller
99 $model = $this->findModel($id); 108 $model = $this->findModel($id);
100 109
101 if ($model->load(Yii::$app->request->post())) { 110 if ($model->load(Yii::$app->request->post())) {
102 -// var_dump($_POST);  
103 -// print "<hr>";  
104 -// var_dump($_FILES);  
105 -// exit;  
106 - if ($model->save()) {  
107 - return $this->redirect(['view', 'id' => $model->brand_id]); 111 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  112 + $model->image = $image->name;
  113 + }
  114 +
  115 + if ($model->save() && $image) {
  116 + $image->saveAs(Yii::getAlias('@imagesDir/brands/' . $image->name));
108 } 117 }
  118 +
  119 + return $this->redirect(['view', 'id' => $model->brand_id]);
109 } else { 120 } else {
110 return $this->render('update', [ 121 return $this->render('update', [
111 'model' => $model, 122 'model' => $model,
backend/controllers/CategoryController.php
@@ -11,6 +11,8 @@ use yii\web\Controller; @@ -11,6 +11,8 @@ use yii\web\Controller;
11 use yii\web\NotFoundHttpException; 11 use yii\web\NotFoundHttpException;
12 use yii\filters\VerbFilter; 12 use yii\filters\VerbFilter;
13 use yii\filters\AccessControl; 13 use yii\filters\AccessControl;
  14 +use yii\web\UploadedFile;
  15 +
14 /** 16 /**
15 * CategoryController implements the CRUD actions for Category model. 17 * CategoryController implements the CRUD actions for Category model.
16 */ 18 */
@@ -79,7 +81,15 @@ class CategoryController extends Controller @@ -79,7 +81,15 @@ class CategoryController extends Controller
79 { 81 {
80 $model = new Category(); 82 $model = new Category();
81 83
82 - if ($model->load(Yii::$app->request->post()) && $model->save()) { 84 + if ($model->load(Yii::$app->request->post())) {
  85 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  86 + $model->image = $image->name;
  87 + }
  88 +
  89 + if ($model->save() && $image) {
  90 + $image->saveAs(Yii::getAlias('@imagesDir/categories/' . $image->name));
  91 + }
  92 +
83 return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->category_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); 93 return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->category_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams));
84 } else { 94 } else {
85 if (!empty(Yii::$app->request->queryParams['parent'])) { 95 if (!empty(Yii::$app->request->queryParams['parent'])) {
@@ -102,7 +112,15 @@ class CategoryController extends Controller @@ -102,7 +112,15 @@ class CategoryController extends Controller
102 { 112 {
103 $model = $this->findModel($id); 113 $model = $this->findModel($id);
104 114
105 - if ($model->load(Yii::$app->request->post()) && $model->save()) { 115 + if ($model->load(Yii::$app->request->post())) {
  116 + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
  117 + $model->image = $image->name;
  118 + }
  119 +
  120 + if ($model->save() && $image) {
  121 + $image->saveAs(Yii::getAlias('@imagesDir/categories/' . $image->name));
  122 + }
  123 +
106 return $this->redirect(['view', 'id' => $model->category_id]); 124 return $this->redirect(['view', 'id' => $model->category_id]);
107 } else { 125 } else {
108 return $this->render('update', [ 126 return $this->render('update', [
backend/views/articles/_form.php
@@ -13,7 +13,10 @@ use yii\jui\DatePicker; @@ -13,7 +13,10 @@ use yii\jui\DatePicker;
13 13
14 <div class="articles-form"> 14 <div class="articles-form">
15 15
16 - <?php $form = ActiveForm::begin(); ?> 16 + <?php $form = ActiveForm::begin([
  17 + 'enableClientValidation' => false,
  18 + 'options' => ['enctype' => 'multipart/form-data']
  19 + ]); ?>
17 20
18 21
19 <?= $form->field($model, 'date') 22 <?= $form->field($model, 'date')
@@ -34,7 +37,21 @@ use yii\jui\DatePicker; @@ -34,7 +37,21 @@ use yii\jui\DatePicker;
34 ]) ?> 37 ]) ?>
35 38
36 39
37 - <?= $form->field($model, 'image')->textInput(['maxlength' => true]) ?> 40 + <?= $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [
  41 + 'language' => 'ru',
  42 + 'options' => [
  43 + 'accept' => 'image/*',
  44 + 'multiple' => false,
  45 + ],
  46 + 'pluginOptions' => [
  47 + 'allowedFileExtensions' => ['jpg', 'gif', 'png'],
  48 + 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '',
  49 + 'overwriteInitial' => true,
  50 + 'showRemove' => false,
  51 + 'showUpload' => false,
  52 + 'previewFileType' => 'image',
  53 + ],
  54 + ]); ?>
38 55
39 <?= $form->field($model, 'translit')->textInput(['maxlength' => true]) ?> 56 <?= $form->field($model, 'translit')->textInput(['maxlength' => true]) ?>
40 57
backend/views/blog/_form.php
@@ -15,7 +15,10 @@ use common\components\Request; @@ -15,7 +15,10 @@ use common\components\Request;
15 15
16 <div class="blog-form"> 16 <div class="blog-form">
17 17
18 - <?php $form = ActiveForm::begin(); ?> 18 + <?php $form = ActiveForm::begin([
  19 + 'enableClientValidation' => false,
  20 + 'options' => ['enctype' => 'multipart/form-data']
  21 + ]); ?>
19 22
20 <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> 23 <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
21 24
@@ -31,20 +34,21 @@ use common\components\Request; @@ -31,20 +34,21 @@ use common\components\Request;
31 ) 34 )
32 ]) ?> 35 ]) ?>
33 36
34 - <?= ImageUploader::widget([  
35 - 'model'=> $model,  
36 - 'field'=>'cover',  
37 - 'size' => [  
38 - [  
39 - 'width'=>340,  
40 - 'height'=>260,  
41 - ] 37 + <?= $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [
  38 + 'language' => 'ru',
  39 + 'options' => [
  40 + 'accept' => 'image/*',
  41 + 'multiple' => false,
42 ], 42 ],
43 - 'multi'=>true,  
44 - 'gallery' =>$model->cover,  
45 - 'name' => 'Загрузить миниатюру статьи'  
46 - ]);  
47 - ?> 43 + 'pluginOptions' => [
  44 + 'allowedFileExtensions' => ['jpg', 'gif', 'png'],
  45 + 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '',
  46 + 'overwriteInitial' => true,
  47 + 'showRemove' => false,
  48 + 'showUpload' => false,
  49 + 'previewFileType' => 'image',
  50 + ],
  51 + ]); ?>
48 52
49 <?= FieldEditor::widget([ 53 <?= FieldEditor::widget([
50 'template' => 'education', 54 'template' => 'education',
backend/views/brand/_form.php
@@ -19,7 +19,21 @@ use yii\widgets\ActiveForm; @@ -19,7 +19,21 @@ use yii\widgets\ActiveForm;
19 19
20 <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> 20 <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?>
21 21
22 - <?= $form->field($model, 'image')->fileInput(['accept' => 'image/*']) ?> 22 + <?= $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [
  23 + 'language' => 'ru',
  24 + 'options' => [
  25 + 'accept' => 'image/*',
  26 + 'multiple' => false,
  27 + ],
  28 + 'pluginOptions' => [
  29 + 'allowedFileExtensions' => ['jpg', 'gif', 'png'],
  30 + 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '',
  31 + 'overwriteInitial' => true,
  32 + 'showRemove' => false,
  33 + 'showUpload' => false,
  34 + 'previewFileType' => 'image',
  35 + ],
  36 + ]); ?>
23 37
24 <?= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?> 38 <?= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?>
25 39
backend/views/brand/view.php
@@ -31,7 +31,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -31,7 +31,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
31 'brand_id', 31 'brand_id',
32 'brand_name_id', 32 'brand_name_id',
33 'alias', 33 'alias',
34 - 'image', 34 + 'imageUrl:image',
35 'meta_title', 35 'meta_title',
36 'meta_desc:ntext', 36 'meta_desc:ntext',
37 'meta_robots', 37 'meta_robots',
backend/views/category/_form.php
@@ -12,7 +12,10 @@ use kartik\select2\Select2; @@ -12,7 +12,10 @@ use kartik\select2\Select2;
12 12
13 <div class="category-form"> 13 <div class="category-form">
14 14
15 - <?php $form = ActiveForm::begin(); ?> 15 + <?php $form = ActiveForm::begin([
  16 + 'enableClientValidation' => false,
  17 + 'options' => ['enctype' => 'multipart/form-data']
  18 + ]); ?>
16 19
17 <?= $form->field($model, 'name')->textInput() ?> 20 <?= $form->field($model, 'name')->textInput() ?>
18 21
@@ -25,13 +28,6 @@ use kartik\select2\Select2; @@ -25,13 +28,6 @@ use kartik\select2\Select2;
25 ] 28 ]
26 ])->label(Yii::t('product', 'Parent category')) ?> 29 ])->label(Yii::t('product', 'Parent category')) ?>
27 30
28 - <?php /*  
29 - <?= $form->field($model, 'group_to_category')->dropDownList(  
30 - \yii\helpers\ArrayHelper::map(\common\modules\rubrication\models\TaxGroup::find()->all(), 'tax_group_id', 'name'), [  
31 - 'multiple' => true  
32 - ])->label(Yii::t('product', 'Linked options')) ?>  
33 - */?>  
34 -  
35 <?= $form->field($model, 'group_to_category')->widget(Select2::className(), [ 31 <?= $form->field($model, 'group_to_category')->widget(Select2::className(), [
36 'data' => \yii\helpers\ArrayHelper::map(\common\modules\rubrication\models\TaxGroup::find()->all(), 'tax_group_id', 'name'), 32 'data' => \yii\helpers\ArrayHelper::map(\common\modules\rubrication\models\TaxGroup::find()->all(), 'tax_group_id', 'name'),
37 'language' => 'ru', 33 'language' => 'ru',
@@ -45,20 +41,21 @@ use kartik\select2\Select2; @@ -45,20 +41,21 @@ use kartik\select2\Select2;
45 ] 41 ]
46 ) ?> 42 ) ?>
47 43
48 - <?= ImageUploader::widget([  
49 - 'model'=> $model,  
50 - 'field'=>'image',  
51 - 'size' => [  
52 - [  
53 - 'width'=>340,  
54 - 'height'=>260,  
55 - ] 44 + <?= $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [
  45 + 'language' => 'ru',
  46 + 'options' => [
  47 + 'accept' => 'image/*',
  48 + 'multiple' => false,
  49 + ],
  50 + 'pluginOptions' => [
  51 + 'allowedFileExtensions' => ['jpg', 'gif', 'png'],
  52 + 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '',
  53 + 'overwriteInitial' => true,
  54 + 'showRemove' => false,
  55 + 'showUpload' => false,
  56 + 'previewFileType' => 'image',
56 ], 57 ],
57 - 'multi'=>false,  
58 - 'gallery' => $model->image,  
59 - 'name' => 'Загрузить изображение'  
60 - ]);  
61 - ?> 58 + ]); ?>
62 59
63 <?= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?> 60 <?= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?>
64 61
backend/views/category/view.php
@@ -36,7 +36,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -36,7 +36,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
36 'parent_id', 36 'parent_id',
37 'path', 37 'path',
38 'depth', 38 'depth',
39 - 'image', 39 + 'imageUrl:image',
40 'meta_title', 40 'meta_title',
41 'meta_desc:ntext', 41 'meta_desc:ntext',
42 'meta_robots', 42 'meta_robots',
common/components/artboximage/ArtboxImageBehavior.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\components\artboximage;
  4 +
  5 +use Yii;
  6 +use yii\base\Behavior;
  7 +
  8 +class ArtboxImageBehavior extends Behavior {
  9 +
  10 +}
0 \ No newline at end of file 11 \ No newline at end of file
common/config/bootstrap.php
@@ -4,3 +4,6 @@ Yii::setAlias(&#39;@frontend&#39;, dirname(dirname(__DIR__)) . &#39;/frontend&#39;); @@ -4,3 +4,6 @@ Yii::setAlias(&#39;@frontend&#39;, dirname(dirname(__DIR__)) . &#39;/frontend&#39;);
4 Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend'); 4 Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
5 Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console'); 5 Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
6 Yii::setAlias('storage', dirname(dirname(__DIR__)) . '/storage'); 6 Yii::setAlias('storage', dirname(dirname(__DIR__)) . '/storage');
  7 +
  8 +Yii::setAlias('@imagesDir', dirname(dirname(__DIR__)) . '/frontend/web/images');
  9 +Yii::setAlias('@imagesUrl', '/images');
common/models/Articles.php
@@ -21,6 +21,8 @@ use Yii; @@ -21,6 +21,8 @@ use Yii;
21 */ 21 */
22 class Articles extends \yii\db\ActiveRecord 22 class Articles extends \yii\db\ActiveRecord
23 { 23 {
  24 + public $imageUpload;
  25 +
24 /** 26 /**
25 * @inheritdoc 27 * @inheritdoc
26 */ 28 */
@@ -39,6 +41,8 @@ class Articles extends \yii\db\ActiveRecord @@ -39,6 +41,8 @@ class Articles extends \yii\db\ActiveRecord
39 [['title', 'body', 'image', 'translit'], 'required'], 41 [['title', 'body', 'image', 'translit'], 'required'],
40 [['body', 'seo_text'], 'string'], 42 [['body', 'seo_text'], 'string'],
41 [['title', 'image', 'translit', 'meta_title', 'meta_keywords', 'meta_description', 'h1'], 'string', 'max' => 255], 43 [['title', 'image', 'translit', 'meta_title', 'meta_keywords', 'meta_description', 'h1'], 'string', 'max' => 255],
  44 + [['imageUpload'], 'safe'],
  45 + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'],
42 ]; 46 ];
43 } 47 }
44 48
@@ -53,6 +57,7 @@ class Articles extends \yii\db\ActiveRecord @@ -53,6 +57,7 @@ class Articles extends \yii\db\ActiveRecord
53 'title' => 'Title', 57 'title' => 'Title',
54 'body' => 'Body', 58 'body' => 'Body',
55 'image' => 'Image', 59 'image' => 'Image',
  60 + 'imageUrl' => Yii::t('app', 'Image'),
56 'translit' => 'Translit', 61 'translit' => 'Translit',
57 'meta_title' => 'Meta Title', 62 'meta_title' => 'Meta Title',
58 'meta_keywords' => 'Meta Keywords', 63 'meta_keywords' => 'Meta Keywords',
@@ -61,4 +66,13 @@ class Articles extends \yii\db\ActiveRecord @@ -61,4 +66,13 @@ class Articles extends \yii\db\ActiveRecord
61 'h1' => 'H1', 66 'h1' => 'H1',
62 ]; 67 ];
63 } 68 }
  69 +
  70 + public function getImageFile() {
  71 + return empty($this->image) ? null : Yii::getAlias('@imagesDir/articles/'. $this->image);
  72 + }
  73 +
  74 + public function getImageUrl()
  75 + {
  76 + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/articles/' . $this->image);
  77 + }
64 } 78 }
common/models/Blog.php
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 */ 21 */
22 class Blog extends \yii\db\ActiveRecord 22 class Blog extends \yii\db\ActiveRecord
23 { 23 {
  24 + public $imageUpload;
24 25
25 /** 26 /**
26 * @inheritdoc 27 * @inheritdoc
@@ -80,6 +81,8 @@ @@ -80,6 +81,8 @@
80 'string', 81 'string',
81 'max' => 255, 82 'max' => 255,
82 ], 83 ],
  84 + [['imageUpload'], 'safe'],
  85 + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'],
83 ]; 86 ];
84 } 87 }
85 88
@@ -102,6 +105,17 @@ @@ -102,6 +105,17 @@
102 'view_count' => Yii::t('app', 'view_count'), 105 'view_count' => Yii::t('app', 'view_count'),
103 'description' => Yii::t('app', 'description'), 106 'description' => Yii::t('app', 'description'),
104 'cover' => Yii::t('app', 'cover'), 107 'cover' => Yii::t('app', 'cover'),
  108 + 'image' => Yii::t('app', 'cover'),
  109 + 'imageUrl' => Yii::t('app', 'cover'),
105 ]; 110 ];
106 } 111 }
  112 +
  113 + public function getImageFile() {
  114 + return empty($this->image) ? null : Yii::getAlias('@imagesDir/brands/'. $this->image);
  115 + }
  116 +
  117 + public function getImageUrl()
  118 + {
  119 + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/brands/' . $this->image);
  120 + }
107 } 121 }
common/modules/product/models/Brand.php
@@ -4,8 +4,7 @@ namespace common\modules\product\models; @@ -4,8 +4,7 @@ namespace common\modules\product\models;
4 4
5 use common\behaviors\Slug; 5 use common\behaviors\Slug;
6 use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; 6 use common\modules\rubrication\behaviors\ArtboxSynonymBehavior;
7 -use mongosoft\file\UploadBehavior;  
8 -use mongosoft\file\UploadImageBehavior; 7 +use yii\web\UploadedFile;
9 use Yii; 8 use Yii;
10 9
11 /** 10 /**
@@ -27,6 +26,8 @@ use Yii; @@ -27,6 +26,8 @@ use Yii;
27 */ 26 */
28 class Brand extends \yii\db\ActiveRecord 27 class Brand extends \yii\db\ActiveRecord
29 { 28 {
  29 + public $imageUpload;
  30 +
30 public function behaviors() 31 public function behaviors()
31 { 32 {
32 return [ 33 return [
@@ -43,18 +44,6 @@ class Brand extends \yii\db\ActiveRecord @@ -43,18 +44,6 @@ class Brand extends \yii\db\ActiveRecord
43 'slugKeyName' => 'alias', 44 'slugKeyName' => 'alias',
44 'translit' => true 45 'translit' => true
45 ], 46 ],
46 - 'uploader' => [  
47 - 'class' => UploadBehavior::className(),  
48 - 'attribute' => 'fileUpload',  
49 - 'scenarios' => ['insert', 'update'],  
50 -// 'placeholder' => '@app/modules/user/assets/images/userpic.jpg',  
51 - 'path' => '@storage/brands/{alias}',  
52 - 'url' => '/storage/brands/{alias}',  
53 -// 'thumbs' => [  
54 -// 'thumb' => ['width' => 400, 'quality' => 90],  
55 -// 'preview' => ['width' => 200, 'height' => 200],  
56 -// ],  
57 - ],  
58 ], 47 ],
59 ]; 48 ];
60 } 49 }
@@ -77,10 +66,10 @@ class Brand extends \yii\db\ActiveRecord @@ -77,10 +66,10 @@ class Brand extends \yii\db\ActiveRecord
77 [['brand_name_id'], 'integer'], 66 [['brand_name_id'], 'integer'],
78 [['meta_desc', 'seo_text'], 'string'], 67 [['meta_desc', 'seo_text'], 'string'],
79 [['alias', 'name'], 'string', 'max' => 250], 68 [['alias', 'name'], 'string', 'max' => 250],
80 - [['meta_title'], 'string', 'max' => 255], 69 + [['meta_title', 'image'], 'string', 'max' => 255],
81 [['meta_robots'], 'string', 'max' => 50], 70 [['meta_robots'], 'string', 'max' => 50],
82 - [['fileUpload'], 'file', 'extensions' => 'jpg, gif, png'],  
83 -// [['brand_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => BrandName::className(), 'targetAttribute' => ['brand_name_id' => 'brand_name_id']], 71 + [['imageUpload'], 'safe'],
  72 + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'],
84 ]; 73 ];
85 } 74 }
86 75
@@ -132,10 +121,11 @@ class Brand extends \yii\db\ActiveRecord @@ -132,10 +121,11 @@ class Brand extends \yii\db\ActiveRecord
132 } 121 }
133 122
134 public function getImageFile() { 123 public function getImageFile() {
135 - return empty($this->image) ? null : '/images/brand/'. $this->image; 124 + return empty($this->image) ? null : Yii::getAlias('@imagesDir/brands/'. $this->image);
136 } 125 }
137 126
138 - public function getImageUrl() {  
139 - return empty($this->image) ? null : '/images/brand/'. $this->image; 127 + public function getImageUrl()
  128 + {
  129 + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/brands/' . $this->image);
140 } 130 }
141 } 131 }
common/modules/product/models/Category.php
@@ -85,7 +85,7 @@ class Category extends \yii\db\ActiveRecord @@ -85,7 +85,7 @@ class Category extends \yii\db\ActiveRecord
85 [['name'], 'string'], 85 [['name'], 'string'],
86 [['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'], 86 [['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'],
87 [['path', 'meta_desc', 'seo_text'], 'string'], 87 [['path', 'meta_desc', 'seo_text'], 'string'],
88 - [['meta_title'], 'string', 'max' => 255], 88 + [['meta_title', 'image'], 'string', 'max' => 255],
89 [['meta_robots'], 'string', 'max' => 50], 89 [['meta_robots'], 'string', 'max' => 50],
90 [['alias', 'name'], 'string', 'max' => 250], 90 [['alias', 'name'], 'string', 'max' => 250],
91 [['populary'], 'boolean'], 91 [['populary'], 'boolean'],
@@ -93,7 +93,6 @@ class Category extends \yii\db\ActiveRecord @@ -93,7 +93,6 @@ class Category extends \yii\db\ActiveRecord
93 [['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']], 93 [['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']],
94 [['imageUpload'], 'safe'], 94 [['imageUpload'], 'safe'],
95 [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], 95 [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'],
96 -// [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']],  
97 ]; 96 ];
98 } 97 }
99 98
@@ -172,14 +171,17 @@ class Category extends \yii\db\ActiveRecord @@ -172,14 +171,17 @@ class Category extends \yii\db\ActiveRecord
172 return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']); 171 return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']);
173 } 172 }
174 173
175 - public function getName()  
176 - { 174 + public function getName() {
177 return empty($this->categoryName) ? null : $this->categoryName->value; 175 return empty($this->categoryName) ? null : $this->categoryName->value;
178 } 176 }
179 177
  178 + public function getImageFile() {
  179 + return empty($this->image) ? null : Yii::getAlias('@imagesDir/categories/'. $this->image);
  180 + }
  181 +
180 public function getImageUrl() 182 public function getImageUrl()
181 { 183 {
182 - return empty($this->image) ? null : '/images/category/' . $this->image; 184 + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/categories/' . $this->image);
183 } 185 }
184 186
185 public function beforeSave($insert) 187 public function beforeSave($insert)
frontend/views/articles/index.php
@@ -27,7 +27,9 @@ $this-&gt;registerMetaTag([&#39;name&#39; =&gt; &#39;keywords&#39;, &#39;content&#39; =&gt; &#39;Блог&#39;]); @@ -27,7 +27,9 @@ $this-&gt;registerMetaTag([&#39;name&#39; =&gt; &#39;keywords&#39;, &#39;content&#39; =&gt; &#39;Блог&#39;]);
27 27
28 <?php foreach($news as $item):?> 28 <?php foreach($news as $item):?>
29 <div class="news_item"> 29 <div class="news_item">
30 - <a href="<?=Url::to(['articles/show','translit'=>$item->translit,'id'=>$item->id])?>"><img src="<?=Yii::$app->request->baseUrl.'/storage/articles/ico/'.$item->image?>" width="180" height="125" border="0" align="left" /></a> 30 + <a href="<?=Url::to(['articles/show','translit'=>$item->translit,'id'=>$item->id])?>">
  31 + <?= \common\components\artboximage\ArtboxImageHelper::getImage($item->imageUrl, 'list')?>
  32 + </a>
31 <a href="<?=Url::to(['articles/show','translit'=>$item->translit,'id'=>$item->id])?>" class="name"><?=$item->title?></a><br /> 33 <a href="<?=Url::to(['articles/show','translit'=>$item->translit,'id'=>$item->id])?>" class="name"><?=$item->title?></a><br />
32 <?=Text::getShort($item->body,600);?><div class="both"></div> 34 <?=Text::getShort($item->body,600);?><div class="both"></div>
33 </div> 35 </div>
frontend/views/articles/show.php
@@ -22,8 +22,7 @@ $this-&gt;registerMetaTag([&#39;name&#39; =&gt; &#39;keywords&#39;, &#39;content&#39; =&gt; $news-&gt;meta_keywords] @@ -22,8 +22,7 @@ $this-&gt;registerMetaTag([&#39;name&#39; =&gt; &#39;keywords&#39;, &#39;content&#39; =&gt; $news-&gt;meta_keywords]
22 22
23 <div class="content"> 23 <div class="content">
24 <h1><?=$news->title?></h1> 24 <h1><?=$news->title?></h1>
25 -  
26 - <img src="<?=Yii::$app->request->baseUrl.'/storage/articles/big/'.$news->image?>" width="400" height="400" border="0" align="left" class='pic' /> 25 + <?= \common\components\artboximage\ArtboxImageHelper::getImage($news->imageUrl, 'product')?>
27 <?=$news->body?> 26 <?=$news->body?>
28 <p class='date'><?=$news->date?></p> 27 <p class='date'><?=$news->date?></p>
29 </div> 28 </div>
frontend/views/catalog/product_item.php
@@ -9,11 +9,7 @@ use yii\helpers\Url; @@ -9,11 +9,7 @@ use yii\helpers\Url;
9 'catalog/product', 9 'catalog/product',
10 'product' => $product]) 10 'product' => $product])
11 ?>"> 11 ?>">
12 - <?php if (empty($product->image)) :?>  
13 - <img src="/img/no_photo.png">  
14 - <?php else :?>  
15 - <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->image->imageUrl, 'list')?>  
16 - <?php endif?> 12 + <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->imageUrl, 'list')?>
17 </a> 13 </a>
18 </div> 14 </div>
19 <a href="<?= Url::to([ 15 <a href="<?= Url::to([