S
S
Sunnat Abdukhalilov2018-12-25 10:32:59
Yii
Sunnat Abdukhalilov, 2018-12-25 10:32:59

Site on yii2, problem with yii2-images, what could be wrong?

everything worked fine, but suddenly pictures stopped being written to the database when adding a product to the site. the image itself is loaded. Everything works locally. but here is the error on hosting

PHP Warning – yii\base\ErrorException
count(): Parameter must be an array or an object that implements Countable

    1. in /home/laffkauz/public_html/vendor/costa-rico/yii2-images/behaviors/ImageBehave.php at line 326
    317318319320321322323324325326327328329330

                         
        /**
         *
         * Обновить алиасы для картинок
         * Зачистить кэш
         */
        private function getAlias()
        {
            $aliasWords = $this->getAliasString();
            $imagesCount = count($this->owner->getImages());
     
            return $aliasWords . '-' . intval($imagesCount + 1);
        }
    }
                    

    2. yii\base\ErrorHandler::handleError(2, 'count(): Parameter must be an ar...', '/home/laffkauz/public_html/vendo...', 326, ...)
    3. in /home/laffkauz/public_html/vendor/costa-rico/yii2-images/behaviors/ImageBehave.php at line 326 – count(yii\db\ActiveQuery)
    320321322323324325326327328329330

                             * Обновить алиасы для картинок
         * Зачистить кэш
         */
        private function getAlias()
        {
            $aliasWords = $this->getAliasString();
            $imagesCount = count($this->owner->getImages());
     
            return $aliasWords . '-' . intval($imagesCount + 1);
        }
    }
                    

    4. in /home/laffkauz/public_html/vendor/costa-rico/yii2-images/behaviors/ImageBehave.php at line 83 – rico\yii2images\behaviors\ImageBehave::getAlias(rico\yii2images\models\Image)
    77787980818283848586878889

                                }
            $image->itemId = $this->owner->primaryKey;
            $image->filePath = $pictureSubDir . '/' . $pictureFileName;
            $image->modelName = $this->getModule()->getShortClass($this->owner);
            $image->name = $name;
     
            $image->urlAlias = $this->getAlias($image);
     
            if(!$image->save()){
                return false;
            }
     
            if (count($image->getErrors()) > 0) {
                    

    5. rico\yii2images\behaviors\ImageBehave::attachImage('upload/store/28690.jpg')
    6. in /home/laffkauz/public_html/vendor/yiisoft/yii2/base/Component.php at line 297 – call_user_func_array([rico\yii2images\behaviors\ImageBehave, 'attachImage'], ['upload/store/28690.jpg'])
    7. in /home/laffkauz/public_html/modules/admin/models/Product.php at line 87 – yii\base\Component::__call('attachImage', ['upload/store/28690.jpg'])
    81828384858687888990919293

                         
        public function uploadGallery(){
            if($this->validate()){
                foreach($this->gallery as $file){
                    $path = 'upload/store/' . $file->baseName . '.' . $file->extension;
                    $file->saveAs($path);
                    $this->attachImage($path);
                    @unlink($path);
                }
                return true;
            }else{
                return false;
            }
                    

    8. in /home/laffkauz/public_html/modules/admin/controllers/ProductController.php at line 93 – app\modules\admin\models\Product::uploadGallery()
    87888990919293949596979899

                                        $model->image = UploadedFile::getInstance($model, 'image');
                    if ($model->image) {
                        $model->upload();
                    }
                    unset($model->image);
                    $model->gallery = UploadedFile::getInstances($model, 'gallery');
                    $model->uploadGallery();
                }
    //            Yii::$app->session->setFlash('success', "Товар {$model->name} обновлен");
                return $this->redirect(['view', 'id' => $model->id]);
            } else {
                return $this->render('update', [
                    'model' => $model,
                    

    9. app\modules\admin\controllers\ProductController::actionUpdate('104')
    10. in /home/laffkauz/public_html/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – call_user_func_array([app\modules\admin\controllers\ProductController, 'actionUpdate'], ['104'])
    11. in /home/laffkauz/public_html/vendor/yiisoft/yii2/base/Controller.php at line 157 – yii\base\InlineAction::runWithParams(['id' => '104'])
    12. in /home/laffkauz/public_html/vendor/yiisoft/yii2/base/Module.php at line 528 – yii\base\Controller::runAction('update', ['id' => '104'])
    13. in /home/laffkauz/public_html/vendor/yiisoft/yii2/web/Application.php at line 103 – yii\base\Module::runAction('admin/product/update', ['id' => '104'])
    14. in /home/laffkauz/public_html/vendor/yiisoft/yii2/base/Application.php at line 386 – yii\web\Application::handleRequest(yii\web\Request)
    15. in /home/laffkauz/public_html/web/index.php at line 13 – yii\base\Application::run()
    78910111213

                        require(__DIR__ . '/../vendor/autoload.php');
    require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
     
    $config = require(__DIR__ . '/../config/web.php');
    require_once __DIR__ .'/../functions.php';
     
    (new yii\web\Application($config))->run(); 
                    

$_GET = [
    'id' => '104',
];

$_POST = [
    '_csrf' => 'dtTNZUycJ9QXTNJUyTbTmzRlksYTxaohWCMn1gpBNMov7aYyFu5_-XAYjWedRKfWXx3_ilD2h04ZEHagJxQNow==',
    'Product' => [
        'cat' => '1',
        'title' => '123',
        'full_title' => '123',
        'price' => '123',
        'description' => '<ol>
    <li>123</li>
</ol>
',
        'gallery' => [
            '',
        ],
        'new' => '1',
        'sale' => '0',
        'available' => '0',
        'active' => '0',
    ],
];

$_FILES = [
    'Product' => [
        'name' => [
            'gallery' => [
                '28690.jpg',
            ],
        ],
        'type' => [
            'gallery' => [
                'image/jpeg',
            ],
        ],
        'tmp_name' => [
            'gallery' => [
                '/tmp/phpAEiKmy',
            ],
        ],
        'error' => [
            'gallery' => [
                0,
            ],
        ],
        'size' => [
            'gallery' => [
                297651,
            ],
        ],
    ],
];

$_COOKIE = [
    'PHPSESSID' => 'fcaafa6e2643ef874b2c89990ebc7b3d',
    '_csrf' => 'fe886b6d2d6b45e8f9d41d172483df057118b42af05e3eca836d1e9580ccd043a:2:{i:0;s:5:"_csrf";i:1;s:32:"Y9kWZrX-gT_3TrtMkxmLC3-oA3Qv-U9i";}',
    '_identity' => '2d4399eea408a176ae9a8315c3cc6a3b2e12408a3745f2e94aa75aaa314c31b0a:2:{i:0;s:9:"_identity";i:1;s:46:"[1,"MUbDNlvQKihzZuWDRTeC9O3ZgNtPDTUb",2592000]";}',
];

$_SESSION = [
    '__flash' => [],
    '__returnUrl' => '/admin/',
    '__id' => 1,
];

help me figure it out please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2018-12-25
@reaferon

It seems to me that your environment is mixed up: DEV is installed on production, and PROD is installed locally.
Since Yii in the DEV environment emits all the warnings, one of which provokes this error (behaviors in yii2-images expects an array or an object, but most likely received a string).
Fix your hosting environment. Not that it is an output, but the error will disappear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question