Commit 0294f8014436c4f6c54d802ca9d1b8b0a8d5b27c
1 parent
543b6b07
Importers CRUD
Showing
5 changed files
with
34 additions
and
24 deletions
Show diff stats
backend/components/base/BaseController.php
| ... | ... | @@ -13,6 +13,11 @@ use yii\web\Controller; |
| 13 | 13 | |
| 14 | 14 | class BaseController extends Controller { |
| 15 | 15 | |
| 16 | + public function beforeAction($action) { | |
| 17 | + $this->enableCsrfValidation = false; | |
| 18 | + return parent::beforeAction($action); | |
| 19 | + } | |
| 20 | + | |
| 16 | 21 | private function resizeImg($w, $h, $imageAlias,$imageAliasSave){ |
| 17 | 22 | $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); |
| 18 | 23 | |
| ... | ... | @@ -37,4 +42,27 @@ class BaseController extends Controller { |
| 37 | 42 | |
| 38 | 43 | } |
| 39 | 44 | |
| 45 | + public function actionDownloadPhoto() | |
| 46 | + { | |
| 47 | + die('here'); | |
| 48 | + $model = new UploadForm(); | |
| 49 | + | |
| 50 | + if ($model->load(Yii::$app->request->post())) { | |
| 51 | + | |
| 52 | + $model->file = UploadedFile::getInstance($model, 'file'); | |
| 53 | + | |
| 54 | + $md5_file = md5_file($model->file->tempName); | |
| 55 | + $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); | |
| 56 | + $imageAlias = Yii::getAlias($imgDir.'480x365'.'.'.$model->file->extension); | |
| 57 | + $imageLink = '/storage/'.$md5_file.'/480x365'.'.'.$model->file->extension; | |
| 58 | + if(!is_dir($imgDir)) { | |
| 59 | + mkdir($imgDir, 0777, true); | |
| 60 | + } | |
| 61 | + $model->file->saveAs($imageAlias); | |
| 62 | + $this->resizeImg(480, 365, $imageAlias,$imageAlias); | |
| 63 | + return json_encode(['link'=>$imageLink]); | |
| 64 | + | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 40 | 68 | } |
| 41 | 69 | \ No newline at end of file | ... | ... |
backend/components/views/image_sizer.php
| ... | ... | @@ -12,12 +12,12 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl |
| 12 | 12 | |
| 13 | 13 | ?> |
| 14 | 14 | |
| 15 | -<?= $form->field($model, 'file')->fileInput(['id'=>$field, 'data-url'=>"index.php?r=site/download-img"]); ?> | |
| 15 | +<?= $form->field($model, 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?> | |
| 16 | 16 | |
| 17 | 17 | <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> |
| 18 | 18 | |
| 19 | 19 | <div id="<?= $field?>_img_block"> |
| 20 | - <?= $model->$field ? Html::img($model->$field): '' ?> | |
| 20 | + <?= $model->$field ? Html::img('/'.$model->$field): '' ?> | |
| 21 | 21 | </div> |
| 22 | 22 | |
| 23 | 23 | <script> |
| ... | ... | @@ -27,6 +27,8 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl |
| 27 | 27 | dataType: 'json', |
| 28 | 28 | done: function (e, data) { |
| 29 | 29 | var host = window.location.host.toString(); |
| 30 | + console.log(host); | |
| 31 | + console.log(data.result.link); | |
| 30 | 32 | var img = '<img src="http://'+host+data.result.link+'">'; |
| 31 | 33 | var block = $("#<?= $field?>_img_block"); |
| 32 | 34 | block.find('img').remove(); | ... | ... |
backend/controllers/UserController.php
| ... | ... | @@ -8,11 +8,11 @@ use backend\models\UserSearch; |
| 8 | 8 | use yii\web\Controller; |
| 9 | 9 | use yii\web\NotFoundHttpException; |
| 10 | 10 | use yii\filters\VerbFilter; |
| 11 | - | |
| 11 | +use backend\components\base\BaseController; | |
| 12 | 12 | /** |
| 13 | 13 | * UserController implements the CRUD actions for User model. |
| 14 | 14 | */ |
| 15 | -class UserController extends Controller | |
| 15 | +class UserController extends BaseController | |
| 16 | 16 | { |
| 17 | 17 | public $layout = "/column"; |
| 18 | 18 | ... | ... |
backend/views/importers/_form.php
| ... | ... | @@ -9,26 +9,6 @@ use backend\models\Currency; |
| 9 | 9 | /* @var $model backend\models\Importers */ |
| 10 | 10 | /* @var $form yii\widgets\ActiveForm */ |
| 11 | 11 | ?> |
| 12 | -<script> | |
| 13 | - var app = angular.module("BackendApp", []); | |
| 14 | - | |
| 15 | - app.controller("SampleAppCtrl", function ($scope) { | |
| 16 | - $scope.hideElem1 = true; | |
| 17 | - $scope.hideElem2 = false; | |
| 18 | - $scope.buttons = [ | |
| 19 | - {status: true, data:'Основные данные'}, | |
| 20 | - {status: false, data:'Обработка прайса (Настройка колонок)'} | |
| 21 | - | |
| 22 | - ]; | |
| 23 | - $scope.ShowMe =function(item){ | |
| 24 | - $scope.buttons.forEach(function(element){ | |
| 25 | - element.status = false; | |
| 26 | - }); | |
| 27 | - item.status = true; | |
| 28 | - } | |
| 29 | - }); | |
| 30 | - | |
| 31 | -</script> | |
| 32 | 12 | <div ng-controller="SampleAppCtrl" class="Importers-form"> |
| 33 | 13 | |
| 34 | 14 | <?php $form = ActiveForm::begin(); ?> | ... | ... |
backend/web/js/angukar_js.js renamed to backend/web/js/angular_js.js