Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: common\models\ImageManager::class()'
in /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/base/Component.php:300
Stack trace:
#0 /var/www/www-homepro/data/www//core/common/models/ImageManager.php(49): yii\base\Component->__call('class', Array)
#1 [internal function]: common\models\ImageManager->common\models\{closure}(Object(common\models\ImageManager), 'sort')
#2 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/validators/DefaultValueValidator.php(48): call_user_func(Object(Closure), Object(common\models\ImageManager), 'sort')
#3 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/validators/Validator.php(267): yii\validators\DefaultValueValidator->validateAttribute(Object(common\models\ImageManager), 'sort')
#4 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/base/Model.php(367): yii\validators\Validator->validateAttributes(Object(common\models\ImageManager), Array)
#5 /var/www/www-homepro/data/www//core/backend/controllers/SiteController.php(112): yii\base\Model->validate()
#6 [internal function]: backend\controllers\SiteController->actionSaveImg()
#7 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#9 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('save-img', Array)
#10 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('site/save-img', Array)
#11 /var/www/www-homepro/data/www//core/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /var/www/www-homepro/data/www//admin/index.php(17): yii\base\Application->run()
#13 {main}
public function getImagesLinksData()
{
return ArrayHelper::toArray($this->images,[
ImageManager::className() => [
'caption' => 'name',
'key' => 'id',
]]
);
}
ImageManager::className() => [
'common/models/ImageManager'=> [
[['sort'], 'default', 'value'=>function($model){
$count = ImageManager::find()->andWhere(['class'=>$model->class()])->count();
return ($count > 0)?$count++:0;
}],
return ($count > 0)?$count++:0;
}],
$model->class()
<?=
\powerkernel\photoswipe\Gallery::widget([
'items' => [
[
'image' => 'https://c2.staticflickr.com/2/1518/24267732553_54aed33368_b.jpg',
'title' => 'Image Title 1',
'caption' => 'Caption 2',
'size' => '1024x685',
'thumb' => 'https://c2.staticflickr.com/2/1518/24267732553_54aed33368_m.jpg',
],
[
'image' => 'https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg',
'title' => 'Image Title 2',
'caption' => 'Caption 3',
'size' => '1024x768',
'thumb' => 'https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg',
],
]
])
?>
foreach ($model->images as $one){
echo Html::img($one->imageUrl,['alt'=>$one->alt]);
}
[
'name' => [
'file' => ''
]
'type' => [
'file' => ''
]
'tmp_name' => [
'file' => ''
]
'error' => [
'file' => 4
]
'size' => [
'file' => 0
]
]
[
'name' => [
'attachment' => ''
]
'type' => [
'attachment' => ''
]
'tmp_name' => [
'attachment' => ''
]
'error' => [
'attachment' => 4
]
'size' => [
'attachment' => 0
]
]
public function beforeDelete()
{
if (parent::beforeDelete()) {
ImageManager::updateAllCounters(['sort' => -1], ['and',['class'=>'blog','item_id'=>$this->item_id], ['>','sort',$this->sort]
]);
return true;
} else {
return false;
}
}
при создании нового поста в блоге.... пост не добавляется
public function actionCreate()
{
$model = new Blog();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
'model' => $model,
11:31:14.616 trace yii\base\Module::getModule Loading module: debug
11:31:14.630 info yii\web\Session::open Session started
11:31:14.643 info yii\db\Command::query SHOW FULL COLUMNS FROM `user`
11:31:14.643 info yii\db\Connection::open Opening DB connection: mysql:host=localhost;dbname=uign
11:31:14.648 info yii\db\Command::query SELECT
kcu.constraint_name,
kcu.column_name,
kcu.referenced_table_name,
kcu.referenced_column_name
FROM information_schema.referential_constraints AS rc
JOIN information_schema.key_column_usage AS kcu ON
(
kcu.constraint_catalog = rc.constraint_catalog OR
(kcu.constraint_catalog IS NULL AND rc.constraint_catalog IS NULL)
) AND
kcu.constraint_schema = rc.constraint_schema AND
kcu.constraint_name = rc.constraint_name
WHERE rc.constraint_schema = database() AND kcu.table_schema = database()
AND rc.table_name = 'user' AND kcu.table_name = 'user'
11:31:14.653 info yii\db\Command::query SELECT * FROM `user` WHERE (`id`=1) AND (`status`=10)
11:31:14.659 trace yii\base\Application::bootstrap Bootstrap with yii\debug\Module::bootstrap()
11:31:14.666 trace yii\base\Application::bootstrap Bootstrap with yii\log\Dispatcher
11:31:14.667 trace yii\web\Application::handleRequest Route requested: 'blog/create'
11:31:14.668 trace yii\base\Controller::runAction Route to run: blog/create
11:31:14.668 trace yii\base\InlineAction::runWithParams Running action: backend\controllers\BlogController::actionCreate()
11:31:14.675 info yii\db\Command::query SHOW FULL COLUMNS FROM `blog`
/core/backend/controllers/BlogController.php:64
11:31:14.676 info yii\db\Command::query SELECT
kcu.constraint_name,
kcu.column_name,
kcu.referenced_table_name,
kcu.referenced_column_name
FROM information_schema.referential_constraints AS rc
JOIN information_schema.key_column_usage AS kcu ON
(
kcu.constraint_catalog = rc.constraint_catalog OR
(kcu.constraint_catalog IS NULL AND rc.constraint_catalog IS NULL)
) AND
kcu.constraint_schema = rc.constraint_schema AND
kcu.constraint_name = rc.constraint_name
WHERE rc.constraint_schema = database() AND kcu.table_schema = database()
AND rc.table_name = 'blog' AND kcu.table_name = 'blog'
/core/backend/controllers/BlogController.php:64
11:31:14.678 info yii\db\ActiveRecord::insert Model not inserted due to validation error.
/core/backend/controllers/BlogController.php:64
11:31:14.680 trace yii\base\View::renderFile Rendering view file: /core/backend/views/blog/create.php
/core/backend/controllers/BlogController.php:69
11:31:14.684 trace yii\base\View::renderFile Rendering view file: /core/backend/views/blog/_form.php
/core/backend/views/blog/create.php:20
/core/backend/controllers/BlogController.php:69
11:31:14.700 info yii\db\Command::query SELECT * FROM `image_manager` WHERE (`class`='blog') AND (0=1) ORDER BY `sort`
/core/common/models/Blog.php:80
/core/backend/views/blog/_form.php:66
/core/backend/views/blog/create.php:20
11:31:14.701 trace yii\base\View::renderFile Rendering view file: /core/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/main.php
/core/backend/controllers/BlogController.php:69
11:31:14.702 trace yii\base\View::renderFile Rendering view file: /core/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php
/core/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/main.php:45
/core/backend/controllers/BlogController.php:69
11:31:14.703 trace yii\base\View::renderFile Rendering view file: /core/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php
/core/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/main.php:50
/core/backend/controllers/BlogController.php:69
11:31:14.704 trace yii\base\View::renderFile Rendering view file: /core/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/content.php
/core/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/main.php:56
/core/backend/controllers/BlogController.php:69
if ($model->load(Yii::$app->request->post()) && $model->save(false)) {
if ($model->load(Yii::$app->request->post())) {
if(!$model->save()){
print_r($model->firstErrors);
die();
}
}
public function actionSortImage($id)
{
if(Yii::$app->request->isAjax){
$post = Yii::$app->request->post('sort');
if($post['oldIndex'] > $post['newIndex']){
$param = ['and',['>=','sort',$post['newIndex']],['<','sort',$post['oldIndex']]];
$counter = 1;
}else{
$param = ['and',['<=','sort',$post['newIndex']],['>','sort',$post['oldIndex']]];
$counter = -1;
}
ImageManager::updateAllCounters(['sort' => $counter], [
'and',['class'=>'blog','item_id'=>$id],$param
]);
ImageManager::updateAll(['sort' => $post['newIndex']], [
'id' => $post['stack'][$post['newIndex']]['key']
]);
return true;
}
throw new MethodNotAllowedHttpException();
}
public function actionSortImage($id)
{
if(Yii::$app->request->isAjax){
$post = Yii::$app->request->post('sort');
if($post['oldIndex'] > $post['newIndex']){
$param = ['and',['>=','sort',$post['newIndex']],['<','sort',$post['oldIndex']]];
$counter = 1;
}else{
$param = ['and',['<=','sort',$post['newIndex']],['>','sort',$post['oldIndex']]];
$counter = -1;
}
ImageManager::updateAllCounters(['sort' => $counter], [
'and',['class'=>'blog','item_id'=>$id],$param
]);
ImageManager::updateAll(['sort' => $post['newIndex']], [
'id' => $post['stack'][$post['newIndex']]['key']
]);
return true;
}
throw new MethodNotAllowedHttpException();
}
<?= \kartik\file\FileInput::widget([
'name' => 'ImageManager[attachment]',
'options'=>[
'multiple'=>true
],
'pluginOptions' => [
'deleteUrl' => Url::toRoute(['/blog/delete-image']),
'initialPreview' => $model->imagesLinks,
'initialPreviewAsData' => true,
'overwriteInitial' => false,
'initialPreviewConfig' => $model->imagesLinksData,
'uploadUrl' => \yii\helpers\Url::to(['/site/save-img']),
'uploadExtraData' => [
'ImageManager[class]' => $model->formName(),
'ImageManager[item_id]' => $model->id,
],
'maxFileCount' => 60,
],
'pluginEvents' => [
'filesorted' => new \yii\web\JsExpression('function(event, params){$.post("'.Url::toRoute(["/blog/sort-image", "id"=>$model->id]).'",{sort:params});
}')
],
]); ?>
$model->imagesLinks
не верная сортировка, проверьте как сортируются данные в связи public function getImages()
{
return $this->hasMany(ImageManager::className(), ['item_id' => 'id'])->andWhere(['class'=>self::tableName()])->orderBy('sort');
}
public function getImagesLinks()
{
return ArrayHelper::getColumn($this->images,'imageUrl');
}
public function getImagesLinksData()
{
return ArrayHelper::toArray($this->images,[
ImageManager::className() => [
'caption'=>'name',
'key'=>'id',
]]
);
}
[['sort'], 'default', 'value' => function($model) {
$count = self::find()->where(['item_id' => $model->item_id])->count();
return $count;
}],