【问题标题】:Using krivochenko/yii2-cropper to upload image doesn't work使用 krivochenko/yii2-cropper 上传图片不起作用
【发布时间】:2021-08-24 05:06:45
【问题描述】:

我不知道我的代码有什么问题,因为我认为,我已经按照 github krivochenko/yii2-cropper 的所有步骤进行操作,但是用于裁剪或删除上传的按钮不起作用,而且表单上显示的 css 也不是像这样整洁:

我在控制台中没有看到任何错误,我想包含我制作的代码:

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>

那么这是在控制器中:

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


那么这段代码有什么问题呢?

【问题讨论】:

    标签: php image yii2 crop


    【解决方案1】:

    终于,我明白我的代码有什么问题了。

    1. 我需要在我自己的小部件中调整 css,并在小部件输入表单中添加参数。:
    <?= $form->field($model, 'imageFile')->widget(Widget::className(), [
       'uploadUrl' => Url::toRoute($uploadPhoto['url']),
       'cropAreaHeight' => 'auto' //here
    ]) ?>
    
    1. 我将Upload Photo index 放入create action,Upload Photo 应该放在function action(general) 中,如下所示:
    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',
            ]
        ];
      }
    

    而且这个小部件krivochenko/yii2-cropper 也可以在yii2中使用也非常容易

    【讨论】:

      猜你喜欢
      • 2013-06-23
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 2017-05-05
      相关资源
      最近更新 更多