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;
}],
<?= \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});
}')
],
]); ?>
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();
}
if ($model->load(Yii::$app->request->post()) && $model->save(false)) {
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
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,
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;
}
}
[
'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
]
]
<?=
\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]);
}
SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value
The SQL being executed was: INSERT INTO `user` (`username`, `email`, `password_hash`, `auth_key`, `status`, `created_at`, `updated_at`) VALUES ('admin', 'info@djeuhf.com', '$2y$13$vHlEf8v/l8cBAHJCTXhIE.Ym/dXVYY1xf5jON0krauRsUDY7y3h6e', 'T4GB6polV8FLBnseLHdlppHUharP4X6D', 10, 1558507436, 1558507436)
Error Info: Array
(
[0] => HY000
[1] => 1364
[2] => Field 'id' doesn't have a default value
)
↵
Caused by: PDOException
SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value