-1

Greetings...

In my sitecontroller i have this code that query the table banner in database.

public function actionIndex()
{
    $model = new Contacto();
    $query = new Query;
    $query->select('foto')
    ->from('banner')
    ->where('id=1');
    $command = $query->createCommand();
    $imagem1 = $command->queryOne();

    $model = new Contacto();
    $query = new Query;
    $query->select('foto')
    ->from('banner')
    ->where('id=2');
    $command = $query->createCommand();
    $imagem2 = $command->queryOne();

    $model = new Contacto();
    $query = new Query;
    $query->select('foto')
    ->from('banner')
    ->where('id=3');
    $command = $query->createCommand();
    $imagem3 = $command->queryOne();

    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        return $this->redirect(Url::toRoute(['site/sucessocontacto']));
    } else {
        return $this->render('index', [
            'model' => $model, 'imagem1' => $imagem1, 'imagem2' => $imagem2, 'imagem3' => $imagem3
        ]);
    }
}

And in my view i have this code:

<?=

    Supersized::widget([
        'theme' => Supersized::THEME_SLIDESHOW,
        'returnType' => Supersized::RETURN_CONTROL,
        'options' => [
            'slide_interval' => 2000,
            'transition' => 1,
            'transition_speed' => 1400,
            'slide_links' => 'blank',
            'random' => 0,
            'slides' => [
                ['image' => implode('', $imagem1)],
                ['image' => implode('', $imagem2)],
                ['image' => implode('', $imagem3)],
            ]
        ]
    ]);
    ?>

This website is finished and works 100% well in my localhost.

I uploaded the website to a live server and it always throws error in the view code. The error is: implode(): Invalid arguments passed

A var_dump $image1 doesn't appear because it gives the error first.

Anyone know why it works like a charm and display all 3 images in a banner working on localhost, but on the live server it always gives this error on implode() function?

PHP version in server is set to 5.5 the one i was developing in localhost.

I tried to declare $image1 2 and 3 vars as an array but didn't work, a var_dump to the vars always showed something similar to array1[0] => bool(false)

I've tried to fix this for the last hours but with no success. I have to go live with the site at the end of the day for testing purposes.

Many thanks to an answer.

André Castro
  • 1,527
  • 6
  • 33
  • 60

1 Answers1

-1

Solved, after figuring out that implode needs to have an array type on live server (in localhost it doesn't argues about that ??!!) and we need to pass the index [0] array to the implode function:

So to close the issue, changing the lines to the following form do it:

 $imagem1[] = $command->queryOne();


['image' => implode('', $imagem1[0])],
André Castro
  • 1,527
  • 6
  • 33
  • 60