abilham
(Andrewbilham)
1
Hi,
I am trying to allocate multiple DB rows into an Array.
<?php
foreach ($photos as $photos) {
$items = ['url' => $photos->location, 'src' => $photos->location, 'options' => array('title' => $photos->name)];
} ?>
it loads but only loads the last img and shows it twice…
im guessing I need to allocate the array in a different way?
Thanks for your help in advanced
tri
(tri - Tommy Riboe)
2
Change every "photos" except the first one to sometning else e.g. "photo".
abilham
(Andrewbilham)
3
Will test this later as having another glitch at the moment.
Cheers
abilham
(Andrewbilham)
4
So, for some reason i just cannot work this out:
View:
<?php foreach($photos as $photo) {
//$Filename = $photo->image_web_filename
$items = [
[
'url' => Yii::$app->params['uploadUrl'] . $photo->image_web_filename,
'src' => Yii::$app->params['uploadUrl'] . 'thumb' . '/' . $photo->image_web_filename,
'options' => array('title' => 'Camposanto monumentale (inside)')
],
];
}
?>
<?= dosamigos\gallery\Gallery::widget(['items' => $items]); ?>
Controller:
/**
* Lists all PhotoPhotos models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new PhotoPhotosSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$photos = PhotoPhotos::find()->all();
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'photos' => $photos,
]);
}
it is just returning the last image not them all… any help please 
rahif
(Rahif)
5
$items is an array of elements,
$items [] = ['url' => $photos->location, 'src' => $photos->location, 'options' => array('title' => $photos->name)];
jacmoe
(Jacob Moena)
6
The problem is that you are defining the array on each iteration.
You need to append to the array instead, as Rahif points out.
abilham
(Andrewbilham)
7
Ah thank you! Always somthing so simple.
Thank you for your help!