Здравствуйте!
У меня аналогичная проблема с установкой
https://github.com/CostaRico/yii2-images
Что не так сделано?
Setup module common/config/main
main.php
Код: Выделить всё
<?php
use \kartik\datecontrol\Module;
return [
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'modules'=>[
'yii2images' => [
'class' => 'rico\yii2images\Module',
//be sure, that permissions ok
//if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
'imagesStorePath' => 'images/store', //path to origin images
'imagesCachePath' => 'images/cache', //path to resized copies
'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
'placeHolderPath' => '@webroot/images/placeHolder.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
],
'datecontrol' => [
'class' => 'kartik\datecontrol\Module',
// format settings for displaying each date attribute (ICU format example)
'displaySettings' => [
Module::FORMAT_DATE => 'yyyy-M-dd',
Module::FORMAT_TIME => 'php: H:i',
Module::FORMAT_DATETIME => 'php:d M Y H:i',
],
// format settings for saving each date attribute (PHP format example)
'saveSettings' => [
Module::FORMAT_DATE => 'php:U',
Module::FORMAT_TIME => 'php:U',
Module::FORMAT_DATETIME => 'php:U',
],
// set your display timezone
'displayTimezone' => 'europe/moscow',
// set your timezone for date saved to db
'saveTimezone' => 'UTC',
// automatically use kartik\widgets for each of the above formats
'autoWidget' => true,
]
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'settings' => [
'class' => 'wokster\settings\components\Settings',
],
'image' => [
'class' => 'yii\image\ImageDriver',
'driver' => 'GD', //GD or Imagick
],
'i18n' => [
'translations' => [
'file-input' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => 'dosamigos\fileinput\src\messages',
],
],
],
],
];
Arcticle.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;
public $image;
/**
* @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(),*/
'class' => 'rico\yii2images\behaviors\ImageBehave',
'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'], 'file', 'extensions' => 'jpg'],
];
}
public function upload(){
if($this->validate()){
$path = 'images/store' . $this->image->baseName . '.' . $this->image->extension;
$this->image->saveAs($path);
return true;
} else {
return false;
}
}
/**
* @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);
}
}
attach behaviour
Arcticle.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;
public $image;
/**
* @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(),*/
'class' => 'rico\yii2images\behaviors\ImageBehave',
'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'], 'file', 'extensions' => 'jpg'],
];
}
public function upload(){
if($this->validate()){
$path = 'images/store' . $this->image->baseName . '.' . $this->image->extension;
$this->image->saveAs($path);
return true;
} else {
return false;
}
}
/**
* @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,
]);
}*/
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->image = UploadedFile::getInstance($model, 'image');
if ($model->image){
$model->upload();
}
return $this->redirect(['view', 'id' => $model->id]);
}
}
/**
* 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
Код: Выделить всё
<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use \dosamigos\fileinput\FileInput;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model wokster\article\models\Article */
/* @var $form yii\widgets\ActiveForm */
/* @var $model app\modules\admin\models\Gallery */
if($model->hasErrors()):
\wokster\ltewidgets\BoxWidget::begin([
'solid'=>true,
'color'=>'danger',
'title'=>'Ошибки валидации',
'close'=> true,
]);
$error_data = $model->firstErrors;
echo \yii\widgets\DetailView::widget([
'model'=>$error_data,
'attributes'=>array_keys($error_data)
]);
\wokster\ltewidgets\BoxWidget::end();
endif;
?>
<div class="-article-form">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'image')->fileInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<div class="article-form">
<?php $form = ActiveForm::begin([
'options' => ['enctype'=>'multipart/form-data'],
'enableClientValidation' => false
]); ?>
<?= $form->field($model, 'title', ['addon' => ['prepend' => ['content' => '<i class="fa fa-pencil"></i>']],'options'=>['class'=>'col-xs-12 col-md-6']])->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'url', ['addon' => ['prepend' => ['content' => '<i class="fa fa-globe"></i>']],'options'=>['class'=>'col-xs-12 col-md-6']])->widget(\wokster\behaviors\TranslitWidget::className())
?>
<?= $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'
]
]
])
?>
<div class="row">
<div class="col-xs-8">
<?= $form->field($model, 'status_id',['options'=>['class'=>'col-xs-12']])->dropDownList(Yii::$app->modules['article']->status_list)
?>
<?= $form->field($model, 'type_id', ['addon' => ['prepend' => ['content' => '<i class="fa fa-pencil"></i>']],'options'=>['class'=>'col-xs-12']])->dropDownList(Yii::$app->modules['article']->type_list) ?>
<div class="<?= ($model->type_id == \wokster\article\Article::TYPE_PAGE)?' hidden':''?>" id="start-date-div">
<?= $form->field($model, 'date_start', ['options'=>['class'=>'col-xs-12']])->widget(\kartik\datecontrol\DateControl::className(),[]) ?>
</div>
<div class="<?= ($model->type_id == \wokster\article\Article::TYPE_SALE)?'':' hidden'?>" id="sale-date-div">
<?= $form->field($model, 'date_finish', ['options'=>['class'=>'col-xs-12']])->widget(\kartik\datecontrol\DateControl::className(),[]) ?>
</div>
<?= $form->field($model, 'new_tags', ['addon' => ['prepend' => ['content' => '<i class="fa fa-pencil"></i>']],'options'=>['class'=>'col-xs-12']])->widget(\wokster\tags\TagsInputWidget::className()) ?>
</div>
<div class="col-xs-4">
<?= $form->field($model, 'file', ['options'=>['class'=>'col-xs-12']])->label(false)->widget(FileInput::className(),[
'attribute' => 'image', // image is the attribute
// using STYLE_IMAGE allows me to display an image. Cool to display previously
// uploaded images
'thumbnail' => '<img src="'.$model->getImage().'" />',
'style' => FileInput::STYLE_IMAGE
]);?>
</div>
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?=$form->field($model, 'image')->fileInput() ?>
</div>
<?= \wokster\seomodule\SeoFormWidget::widget(['model'=>$model,'form'=>$form]);?>
<div class="row">
<div class="col-xs-12 col-md-12">
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' =>'btn btn-success']) ?>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php $this->registerJs("
$('#article-type_id').on('change',function(){
var type = $(this).val();
if(type == ".\wokster\article\Article::TYPE_SALE."){
$('#sale-date-div').removeClass('hidden');
$('#start-date-div').removeClass('hidden');
}else if(type == ".\wokster\article\Article::TYPE_NEWS."){
$('#sale-date-div').addClass('hidden');
$('#start-date-div').removeClass('hidden');
}else{
$('#sale-date-div').addClass('hidden');
$('#start-date-div').addClass('hidden');
}
});
");
В итоге у меня сейчас ошибка: