@Maila

Почему не загружается картинка?

В поле загрузки появляется окно, после выбора фото загрузка не происходит. Дебаг ошибок не выводит. Использую vova07\imperavi\Widget и yurkinx/yii2-image. Драйвер менялся на GD и Imagick, версии php -тоже.

Article.php
<?php

namespace wokster\article\models;

use wokster\behaviors\ImageUploadBehavior;
use wokster\behaviors\StatusBehavior;
use wokster\tags\TagsBehavior;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\helpers\StringHelper;
use yii\helpers\Url;


/**
 * This is the model class for table "article".
 *
 * @property integer $id
 * @property string $title
 * @property string $url
 * @property string $text
 * @property integer $status_id
 * @property string $image
 * @property integer $date_create
 * @property integer $type_id
 * @property integer $date_start
 * @property integer $date_finish

 */
class Article extends \yii\db\ActiveRecord
{
    public $file;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'article';
    }

    /**
    * @inheritdoc
    */
    public function behaviors()
    {
        return [
            'status' => [
              'class' => StatusBehavior::className(),
              'status_value' => $this->status_id,
               'statusList' => Yii::$app->modules['article']->status_list,
            ],
            'image' => [
                'class' => ImageUploadBehavior::className(),
                'attribute' => 'image',
                'random_name' => 'true',
                'image_path' => Yii::$app->modules['article']->imagePath,
                'image_url' => Yii::$app->modules['article']->imageUrl,
                'size_for_resize' => [
                                [640,480,true],
                                [640,null,false],
                                [50,50,true]
                                ]
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'date_create',
                'updatedAtAttribute' => false,
            ],
            'seo' => [
                'class' => \wokster\seomodule\SeoBehavior::className(),
            ],
            'tags' => [
                'class' => TagsBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'url'], 'required'],
            [['date_start', 'date_finish'], 'required', 'when' => function($model) {
                return $model->type_id == \wokster\article\Article::TYPE_SALE;
            }],
            [['text'], 'string'],
            [['status_id', 'date_create', 'type_id', 'date_start', 'date_finish'], 'integer'],
            [['title', 'image'], 'string', 'max' => 255],
            [['url'], 'string', 'max' => 100],
            [['url'], 'unique'],
           

            [['url'], 'match', 'pattern' => '/^[a-z0-9_-]+$/', 'message' => 'Недопустимые символы в url'],
            [['status_id'], 'default','value'=>0],
            ['file','image'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'заглавие',
            'url' => 'ЧПУ',
            'text' => 'контент',
            'status_id' => 'статус',
            'image' => 'картинка',
            'date_create' => 'дата публикации',
            'type_id' => 'тип',
            'Status' => 'статус',
      
            'date_start' => 'дата начала',
            'date_finish' => 'дата окончания'
        ];
    }

    /**
     * @return mixed
     */
    public static function getTypeList(){
        return Yii::$app->modules['article']->type_list;
    }

    /**
     * @return string
     */
    public function getTypeName(){
        $list = self::getTypeList();
        return (isset($list[$this->type_id]))?$list[$this->type_id]:'';
    }

    /**
     * @return string
     */
    public function getShortText(){
        return StringHelper::truncateWords(strip_tags($this->text),50);
    }
}

ArcticleController

<?php

namespace wokster\article\controllers;

use yii;
use wokster\article\models\Article;
use wokster\article\models\ArticleSearch;
use yii\web\MethodNotAllowedHttpException;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * ArticleController implements the CRUD actions for Article model.
 */
class ArticleController extends yii\web\Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }


    public function actions()
    {
        return [
            'images-get' => [
                'class' => 'vova07\imperavi\actions\GetAction',
                'url' => \Yii::$app->controller->module->allRedactorImageUrl, // Directory URL address, where files are stored.
                'path' => \Yii::$app->controller->module->redactor_upload_path_alias, // Or absolute path to directory where files are stored.
                'type' => \vova07\imperavi\actions\GetAction::TYPE_IMAGES,
            ],
            'image-upload' => [
                'class' => 'vova07\imperavi\actions\UploadAction',
                'url' => \Yii::$app->controller->module->redactorImageUrl, // Directory URL address, where files are stored.
                'path' => \Yii::$app->controller->module->redactorPath, // Or absolute path to directory where files are stored.
            ],
        ];
    }

    /**
     * Lists all Article models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new ArticleSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single Article model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new Article model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate($type=null)
    {
        $model = new Article();
        if(is_numeric($type))
            $model->type_id = $type;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            if(Yii::$app->request->post('toview',false)){
                return $this->redirect(['view', 'id' => $model->id]);
            }else{
                return $this->redirect(['update', 'id' => $model->id]);
            }

        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Updates an existing Article model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['update', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing Article model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }


    /**
     * Finds the Article model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Article the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Article::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}


form.php
<?= $form->field($model, 'text',['options'=>['class'=>'col-xs-12']])->widget(\vova07\imperavi\Widget::className(),[
'settings' => [
'lang' => 'ru',
'minHeight' => 200,
'pastePlainText' => true,
'imageUpload' => \yii\helpers\Url::toRoute(['/article/article/image-upload']),
'imageManagerJson' => \yii\helpers\Url::toRoute(['/article/article/images-get']),
/*'imageUpload' => \yii\helpers\Url::to (['/site/save-redactor-img']),*/
'replaceDivs' => false,
'formattingAdd' => [
[
'tag' => 'p',
'title' => 'text-success',
'class' => 'text-success'
],
[
'tag' => 'p',
'title' => 'text-danger',
'class' => 'text-danger'
],
],
'plugins' => [
'fullscreen',
'table',
'imagemanager',
'fontcolor',
'fontsize',
'video'
]
]
])

?>
  • Вопрос задан
  • 193 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы