1
試圖獲得yii2先進的工作與Redactor,文本區域可以顯示,但圖像插入失敗。總是得到錯誤POST和GET錯誤500. 我已經使用Yii2網站上的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調試在底部,並檢查錯誤,發現錯誤一直在說:
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}
然後我去主編檢查模塊的配置:
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 /上傳,我已經成功地在之前UploadedFile的測試上傳的圖片。 此外,試圖手動分配索引「ClientOptions」多次的目錄,問題仍然存在。小工具的
謝謝你,你的鏈接來解決問題。只是想知道我用關鍵詞搜索了谷歌,那個頁面不是結果,你是怎麼找到它的。 – newbrant
嗯,我在github回購中發現了這個錯誤文本,並發現開發人員更改了代碼以防止出現錯誤。 –