yii2 高级编辑器图像上传失败并出现错误 'Invalid config $uploadDir'
yii2 advanced redactor image upload fail with error 'Invalid config $uploadDir'
试图让 yii2 Advanced 与 Redactor 一起工作,文本区域可以显示,但图像插入失败。始终收到错误 POST 和 GET 错误 500。
我用Yii2 web 上的UploadedFile 教程测试过,图片可以成功上传并显示在目录中,但是redactor 无法工作。
这是我的文章管理员:
namespace backend\controllers;
use yii\web\Controller;
use common\models\Article;
use Yii;
class ArticleController extends Controller{
public $layout='empty';
public function actionIndex(){
$model = new Article;
if($model->load(Yii::$app->request->post()) && $model->validate()){
echo "good operation";
}
return $this->render('index', ['model'=>$model]);
}
这是我的模型:
namespace common\models;
use yii\db\ActiveRecord;
use Yii;
class Article extends ActiveRecord{
//const SCENARIO_LOGIN = 'login';
//const SCENARIO_REGISTER = 'register';
public static function tableName(){
return '{{%article}}';
}
public function rules(){
return [
[['title','description','content'],'required','message'=>'{attribute} required'],
['title','unique','message'=>'sorry,{value} is taken'],
['status','in','range'=>[0,1]],
];
}
}
并查看:
<?php
use yii\helpers\Url;
use yii\widgets\Breadcrumbs;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?=Breadcrumbs::widget([
'homeLink'=> ['label'=>'Home'],
'links'=> [
['label'=>'Add New Article'],
],
])?>
<?php
$form = ActiveForm::begin([
'id'=>'article',
'options'=>['class'=>'wenzhang'],
]);
?>
<?=$form->field($model, 'title')?>
<?=$form->field($model,'description')?>
<?=$form->field($model,'content')->widget(\yii\redactor\widgets\Redactor::className(),
[
'clientOptions'=>[
'imageManagerJson' =>['/redactor/upload/image-json'],
'lang'=>'zh_cn',
'plugins'=>['clips','fontcolor','imagemanager'],
'imageUpload' => \yii\helpers\Url::to(['/redactor/upload/image']),
],
]
)?>
<button>Submit</button>
<?php ActiveForm::end()?>
我在最下面打开yii2 debug查看错误,发现错误一直在说:
exception 'yii\base\InvalidConfigException' with message 'Invalid config $uploadDir' in /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiidoc/yii2-redactor/RedactorModule.php:51
Stack trace:
#0 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiidoc/yii2-redactor/actions/ImageManagerJsonAction.php(33): yii\redactor\RedactorModule->getSaveDir()
#1 [internal function]: yii\redactor\actions\ImageManagerJsonAction->run()
#2 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Action.php(92): call_user_func_array(Array, Array)
#3 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\Action->runWithParams(Array)
#4 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('image-json', Array)
#5 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/web/Application.php(100): yii\base\Module->runAction('redactor/upload...', Array)
#6 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#7 /home/ubuntu/workspace/yii2AdvancedTest/backend/web/index.php(18): yii\base\Application->run()
#8 {main}
然后我去 Redactor 模块检查配置:
public $controllerNamespace = 'yii\redactor\controllers';
public $defaultRoute = 'upload';
public $uploadDir = '@webroot/uploads';
public $uploadUrl = '@web/uploads';
public $imageUploadRoute = ['/redactor/upload/image'];
public $fileUploadRoute = ['/redactor/upload/file'];
public $imageManagerJsonRoute = ['/redactor/upload/image-json'];
public $fileManagerJsonRoute = ['/redactor/upload/file-json'];
public $imageAllowExtensions = ['jpg', 'png', 'gif', 'bmp', 'svg'];
一切似乎都设置正确,并且在 /web/uploads 上,我已经在之前的 UploadedFile 测试中成功上传了图像。
此外,多次尝试手动分配索引 "ClientOptions" 上的目录,问题仍然存在。
更新您的小部件版本,如您在此处所见
Github,开发人员进行了一些更改以防止出现此错误
试图让 yii2 Advanced 与 Redactor 一起工作,文本区域可以显示,但图像插入失败。始终收到错误 POST 和 GET 错误 500。 我用Yii2 web 上的UploadedFile 教程测试过,图片可以成功上传并显示在目录中,但是redactor 无法工作。
这是我的文章管理员:
namespace backend\controllers;
use yii\web\Controller;
use common\models\Article;
use Yii;
class ArticleController extends Controller{
public $layout='empty';
public function actionIndex(){
$model = new Article;
if($model->load(Yii::$app->request->post()) && $model->validate()){
echo "good operation";
}
return $this->render('index', ['model'=>$model]);
}
这是我的模型:
namespace common\models;
use yii\db\ActiveRecord;
use Yii;
class Article extends ActiveRecord{
//const SCENARIO_LOGIN = 'login';
//const SCENARIO_REGISTER = 'register';
public static function tableName(){
return '{{%article}}';
}
public function rules(){
return [
[['title','description','content'],'required','message'=>'{attribute} required'],
['title','unique','message'=>'sorry,{value} is taken'],
['status','in','range'=>[0,1]],
];
}
}
并查看:
<?php
use yii\helpers\Url;
use yii\widgets\Breadcrumbs;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?=Breadcrumbs::widget([
'homeLink'=> ['label'=>'Home'],
'links'=> [
['label'=>'Add New Article'],
],
])?>
<?php
$form = ActiveForm::begin([
'id'=>'article',
'options'=>['class'=>'wenzhang'],
]);
?>
<?=$form->field($model, 'title')?>
<?=$form->field($model,'description')?>
<?=$form->field($model,'content')->widget(\yii\redactor\widgets\Redactor::className(),
[
'clientOptions'=>[
'imageManagerJson' =>['/redactor/upload/image-json'],
'lang'=>'zh_cn',
'plugins'=>['clips','fontcolor','imagemanager'],
'imageUpload' => \yii\helpers\Url::to(['/redactor/upload/image']),
],
]
)?>
<button>Submit</button>
<?php ActiveForm::end()?>
我在最下面打开yii2 debug查看错误,发现错误一直在说:
exception 'yii\base\InvalidConfigException' with message 'Invalid config $uploadDir' in /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiidoc/yii2-redactor/RedactorModule.php:51
Stack trace:
#0 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiidoc/yii2-redactor/actions/ImageManagerJsonAction.php(33): yii\redactor\RedactorModule->getSaveDir()
#1 [internal function]: yii\redactor\actions\ImageManagerJsonAction->run()
#2 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Action.php(92): call_user_func_array(Array, Array)
#3 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\Action->runWithParams(Array)
#4 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('image-json', Array)
#5 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/web/Application.php(100): yii\base\Module->runAction('redactor/upload...', Array)
#6 /home/ubuntu/workspace/yii2AdvancedTest/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#7 /home/ubuntu/workspace/yii2AdvancedTest/backend/web/index.php(18): yii\base\Application->run()
#8 {main}
然后我去 Redactor 模块检查配置:
public $controllerNamespace = 'yii\redactor\controllers';
public $defaultRoute = 'upload';
public $uploadDir = '@webroot/uploads';
public $uploadUrl = '@web/uploads';
public $imageUploadRoute = ['/redactor/upload/image'];
public $fileUploadRoute = ['/redactor/upload/file'];
public $imageManagerJsonRoute = ['/redactor/upload/image-json'];
public $fileManagerJsonRoute = ['/redactor/upload/file-json'];
public $imageAllowExtensions = ['jpg', 'png', 'gif', 'bmp', 'svg'];
一切似乎都设置正确,并且在 /web/uploads 上,我已经在之前的 UploadedFile 测试中成功上传了图像。 此外,多次尝试手动分配索引 "ClientOptions" 上的目录,问题仍然存在。
更新您的小部件版本,如您在此处所见 Github,开发人员进行了一些更改以防止出现此错误