Hello,
I am following your simple modules tutorial.
I need to create a block that displays a list of cheeses from the cheeses table on the home page.
In MY_fuel_modules I added:
$config['modules']['cheeses'] = array(
'preview_path' => 'cheeses/{slug}',
'display_field' => 'cheese_name',
'sanitize_input' => array('template','php'),
// 'view_location' => Not sure what to put here...
);
On views/_layouts/main.php I added:
<?php echo fuel_block('our_cheeses'); ?>
I created this block: views/_blocks/cheese/our_cheeses.php
The code:
$slug = uri_segment(2);
if ($slug):
$cheese = fuel_model('cheeses', array('find' => 'one', 'where' => array('slug' => $slug)));
if (empty($cheese)) :
redirect_404();
endif;
else:
$cheeses = fuel_model('cheeses');
endif;
if (!empty($cheese)) : ?>
<?=fuel_edit($cheese)?><?=$cheese->cheese_name?>
![image](src)
image_path?>" alt="<?=$cheese->title_entities?>" class="img_right">
<?=$cheese->cheese_desc?>
<?php else: ?>
Cheeses
<?=fuel_edit('create', 'Create Cheese', 'cheeses')?>
Our Cheese
<?php foreach($cheeses as $cheese) : ?>
<?php endforeach; ?>
But when I go to the home page, the block does not display.
What am I missing?
Comments
<?php echo fuel_block('cheeses/our_cheeses'); ?>
I have a question. What happen when you want more than one result? I reffered to this line:
$cheese = fuel_model('cheeses', array('find' => 'one', 'where' => array('slug' => $slug)));
How i can change the code to obtain more than one data? Thanks a lot.
I guess you would use this: $cheeses = fuel_model('cheeses');