yii2高级编解码器图像上载失败,出现错误';无效配置$uploadDir';
尝试使用Redactor获得Yi2高级工作,文本区域可以显示,但图像插入失败。始终获取错误帖子并获取错误500。 我已经在Yii2Web上使用UploadedFile教程进行了测试,图像可以成功上传并显示在目录中,但redactor无法工作 以下是我的文章:yii2高级编解码器图像上载失败,出现错误';无效配置$uploadDir';,yii2,redactor,Yii2,Redactor,尝试使用Redactor获得Yi2高级工作,文本区域可以显示,但图像插入失败。始终获取错误帖子并获取错误500。 我已经在Yii2Web上使用UploadedFile教程进行了测试,图像可以成功上传并显示在目录中,但redactor无法工作 以下是我的文章: namespace backend\controllers; use yii\web\Controller; use common\models\Article; use Yii; class ArticleController ext
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()?>
然后我转到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 repo中找到了这个错误文本,并发现开发人员更改代码以防止错误。
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'];