Answer the question
In order to leave comments, you need to log in
Output photos from the database, photo gallery, I can not display, how to output?
Hello.
I think it doesn't matter which framework I use, but in general ko7 , kohana .
I made a photo gallery, photos are added, everything is in the database, but I can’t bring it to the front in the photo gallery.
Knowledge is not great, I'm still learning, I did it following the example of other controllers, where there is a photo output.
Database structure, photo gallery table fotogalerejas.
Fields:
id - id of the photo gallery
images_id - id of the photo
The structure of the images table, here the name of the photo is stored, plus positions.
Fields:
id - id of the photo image - the name of the
image is written here
pos - this is the position of the photo
fotogalereja_id- photo gallery
id Table screen fotogalerejas Table screen
images (unnecessary hidden)
Photo gallery controller
$id = (int)$this->request->param('id', '=', '1');
$fotogalerejas = ORM::factory('Fotogalereja')->find_all();
$images = ORM::factory('Image')
->where('fotogalereja_id', '=', $id)
->find_all();
$content = View::factory('index/main/fotogalereja')
->set('fotogalerejas', $fotogalerejas)
->set('images', $images);
<? foreach ($fotogalerejas as $fotogalerejas) : ?>
<?php echo $fotogalerejas->images->image ?>
<?php echo $fotogalerejas->image_id ?>
<? endforeach ?>
class Model_Fotogalereja extends ORM
{
protected $_table_name = 'fotogalerejas';
protected $_primary_key = 'id';
protected $_db_group = 'default';
protected $_has_many = array(
'images' => array(
'model' => 'Image',
'foreign_key' => 'fotogalereja_id',
),
);
protected $_belongs_to = array(
'main_img' => array(
'model' => 'Image',
'foreign_key' => 'image_id',
),
);
}
1) $images = ORM::factory('Image')
2) ->where('fotogalereja_id', '=', $id)
3) ->find_all();
Answer the question
In order to leave comments, you need to log in
So I fixed it myself: Added to the
controller
$images = ORM::factory('Image')
->order_by('pos', 'ASC')
->where('fotogalereja_id', '=', $fotogalerejas->id)
->find_all();
$content = View::factory('index/main/fotogalereja')
->set('fotogalerejas', $fotogalerejas)
->set('images_all', $images);
<?php foreach ($images_all as $image) : ?>
<?php echo $image->image ?>
<?php endforeach ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question