Search code examples
phpimageyii2crop

Using krivochenko/yii2-cropper to upload image doesn't work


I don't know what's wrong with my code because i think, i have following all the step from github krivochenko/yii2-cropper But button to cropping or delete upload doesn't work and and also the css displayed on the form is not neat like this :

capture

i'm not see any error in console, and i want to include the code i made :

this is in view :

use budyaga\cropper\Widget;

<div class="form-group col-sm-8 col-md-8 col-lg-6">
   <?= $form->field($model, 'imageFile')->widget(Widget::className(), [
      'uploadUrl' => Url::toRoute($uploadPhoto['url']),
      ]) ?>
</div>

then this is in controller:

return $this->render('input', [
      'model' => $model,
      'uploadPhoto' => [
            'class' => 'budyaga\cropper\actions\UploadAction',
            'url' => 'content/user/create',
            'path' => $this->baseApp.'/files/uploads',
        ]
    ]);


So what's wrong with this code?


Solution

  • finally, i can understand what wrong with my code.

    1. I need to adjust css from this widget in my own with add param in widget input form.:
    <?= $form->field($model, 'imageFile')->widget(Widget::className(), [
       'uploadUrl' => Url::toRoute($uploadPhoto['url']),
       'cropAreaHeight' => 'auto' //here
    ]) ?>
    
    1. i put Upload Photo index into create action, Upload Photo should be placed in function action(general) like this:
    public function actions()
      {
        return [
          'error' => [
            'class' => 'yii\web\ErrorAction',
          ],
          'uploadPhoto' => [
              'class' => 'budyaga\cropper\actions\UploadAction',
              'url' => 'dir_to_save_the_result_of_crop',
              'path' => 'path_to_save_the_result_of_crop',
            ]
        ];
      }
    

    And this widget krivochenko/yii2-cropper can works also really easy to use in yii2