bupy7 / yii2-widget-cropbox

This widget allows crop image before upload to server and send informations about crop in JSON format.
BSD 3-Clause "New" or "Revised" License
91 stars 33 forks source link

Undefined index: cropSettings #36

Closed hfageeh closed 7 years ago

hfageeh commented 7 years ago

I dont know what wrong I just install it as you said step by step please advise

bupy7 commented 7 years ago

What version of cropbox? And could you give me your code?

hfageeh commented 7 years ago

3.0

hfageeh commented 7 years ago

view:

<?php

use yii\helpers\Html; use yii\widgets\ActiveForm; use bupy7\cropbox\Cropbox; / @var $this yii\web\View / / @var $model backend\models\Projectsgroups / / @var $form yii\widgets\ActiveForm / ?>

['enctype' => 'multipart/form-data']]) ?> field($model, 'image')->widget(Cropbox::className(), [ 'attributeCropInfo' => 'crop_info', ]); ?> field($model, 'order')->textInput() ?> field($model, 'ar_groupname')->textInput(['maxlength' => true]) ?> field($model, 'en_groupname')->textInput(['maxlength' => true]) ?>
isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
hfageeh commented 7 years ago

model:

<?php

namespace backend\models;

use Yii; use yii\helpers\FileHelper; use yii\imagine\Image; use yii\helpers\Json; use Imagine\Image\Box; use Imagine\Image\Point; /**

hfageeh commented 7 years ago

controller: public function actionCreate() { $model = new Projectsgroups(); //$upload = new UploadForm(); if ($model->load(Yii::$app->request->post())) { // get uploaded file information $groupName = strtolower($model->en_groupname); $imageName = str_replace(' ', '',$groupName );; $model->image = UploadedFile::getInstance($model, 'image'); $model->image->saveAs('../../frontend/web/images/project/' . $imageName.'.'.$model->image->extension);

        // save the path in DB 
        $model->imageFile = $imageName.'.'.$model->image->extension;
        $model->created = date('Y-m-d h:m:s');
        $model->save();

        return $this->redirect(['view', 'id' => $model->projgroup_id]);
        } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}
bupy7 commented 7 years ago

Wow, very dirty... You should wrap you code in markdown code tag, please.

Could you give me screenshot of the error message?

hfageeh commented 7 years ago
error
bupy7 commented 7 years ago

It's a bug. You can fix it following code or use 4 version of cropbox:

<?= $form->field($model, 'image')->widget(Cropbox::className(), [
    'attributeCropInfo' => 'crop_info',
    'optionsCropbox' => [
        'cropSettings' => [],
    ],
]); ?>
hfageeh commented 7 years ago

The 'icon-framework' option has not been setup in Yii params. Check your configuration file.

bupy7 commented 7 years ago

https://github.com/kartik-v/yii2-icons#global-setup

hfageeh commented 7 years ago

its work you the man 💯