A
A
Anton2015-12-08 06:44:35
Kohana
Anton, 2015-12-08 06:44:35

We display a picture from a category on the main page in a block, how to display it by id?

Hello, I'm trying to display on the main page of the site in the block a picture from a category by id, I managed to display all the images of the categories, but how to display from a specific category, exactly from the one I want id 858.
In the template, the code for output:

<?php foreach ($categories as $cat):?>
<img src="/media/uploads/cat/<?=$cat['catimage']?>"/>
<?php endforeach; ?>

/application/classes/controller
index.php
Added this:
$cat_id = 858;
$cats = ORM::factory('category')->where('parent_id', '=', $cat_id)->find_all();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Vasilkov, 2015-12-08
@gzhegow

So you do this:

<?
print_r($cat);
die();
?>

See if your field from the base with the picture is there at all. Can pictures are stored in other table, m?
--
and then, selecting through find_all you receive all records.
I'm sure your ORM has a find() method that gives you one entry.
If not, then do this:
$val = reset($cats);
echo $val['catimage'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question