A
A
Anton2021-02-20 14:57:37
Kohana
Anton, 2021-02-20 14:57:37

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
6030f71603604691938538.png

images (unnecessary hidden)
6030f7a247419010762350.png

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);


Output in a template
<? foreach ($fotogalerejas as $fotogalerejas) : ?>
  <?php echo $fotogalerejas->images->image ?>
  <?php echo $fotogalerejas->image_id ?>
  <? endforeach ?>


I output the id of the photo (<?php echo $fotogalerejas->image_id ?>), this is for example, to understand that everything is ok, the id displays.
I'm trying to display an image <?php echo $fotogalerejas->images->image ?> so far nothing.

In the fotogalereja model I have this:
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',
    ),
  );
}


As I understand this part of the code.
1)    $images = ORM::factory('Image')
2)    ->where('fotogalereja_id', '=', $id)
3)    ->find_all();


1) load the table from the images/
database 2) find the fotogalereja_id field with id 1 in the images table, this is the photo gallery id
3) print everything we found.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2021-02-21
Websaytovsky @ws17

So I fixed it myself: Added to the
controller

$images = ORM::factory('Image')
    ->order_by('pos', 'ASC')
    ->where('fotogalereja_id', '=', $fotogalerejas->id)
      ->find_all();

And pass it to the template
$content = View::factory('index/main/fotogalereja')
      ->set('fotogalerejas', $fotogalerejas)
      ->set('images_all', $images);

In the output template
<?php foreach ($images_all as $image) : ?>
<?php echo $image->image ?>
<?php endforeach ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question