I am working with a foreach loop and I want to make some banners in
frontend/layouts/main
I created a model where I have these static functions:
public static function getUrl() {
return Banner::find()->where(['Rel_User' => Yii::$app->user->identity->Id])->all();
}
public static function getImage() {
return Yii::$app->basePath . '/web/' . $this->Image;
}
And I want to display this URL in my main:
<?php foreach (Banner::getUrl() as $key): ?>
<div class="banner">
<a href="<?= $key['Url'] ?>" title="">
<img src="<?=Url::base(true)?>/img/banner.jpg" alt=""></a>
</div>
<?php endforeach; ?>
The problem is that I have 3 banners assigned to the logged user and this loop displays only one banner. What did I do wrong? My second question is, what should I do to display only the URL from my database, because now the URL looks like:
http://my-page.frontend.localhost/www.google.com
but in my database it is:
url= www.google.com