Today I made a details page and a list of items. It works well, but pictures are not shown. As you see bellow, image src is empty. I checked it in itemName.xml file and in Item Manager interface and image src have to be.
The path of image is "/home/ppiczosn/public_html/ihrashky/data/uploads/imanager/pokupat-detskie-veschi-v-magazine-prosto.jpg" (I took this path from Item Manager => Edit Item => File select Field.
Here is my php components:
Code:
<div id="manager"><div class="im-resultwrap"><a class="im-itempic" href="item-manager-details-page?item=test-shop"><img alt="" class="im-pic" src=""><span class="im-hidden"></span></a></div>...<div class="paginator-wrapper"></div>
</div>
The path of image is "/home/ppiczosn/public_html/ihrashky/data/uploads/imanager/pokupat-detskie-veschi-v-magazine-prosto.jpg" (I took this path from Item Manager => Edit Item => File select Field.
Here is my php components:
PHP Code:
<?php
// create controller instance
$manager = new ImController();
// setup category
ImCategory::setCategory('Stores');
// limiting items per page
ImModel::setPref('itemsperpage', 10);
// setup sort by field
ImModel::setPref('sortby', 'sequence');
// setup details page
ImModel::setPref('page', 'item-manager-details-page');
/* Run action: generates item register calculated out of all the mentioned parameters.
For this example's purpose, we'll need two custom fields in our List view: a 'thumb' to
display as a link to our Details page and 'sequence' to determine the order of products
displayed. */
$manager->runModelMethod('gen_register', array('loop-thumb-1', 'sequence'));
/* This method returns an array which contains multiple item data specified by gen_register and
depending on the settings made. */
$items = $manager->getModelValue('items_ordered_struct');
// Returns a page data array based on the settings made
$pagedata = $manager->getModelValue('pagedata');
// templates as strings, just for demonstration
if(!$manager->tplRegister(array('loop' =>
'<div class="im-resultwrap">'
.'<a class="im-itempic" href="[[page]]?item=[[ slug ]]"><img alt="" class="im-pic" src="[[loop-thumb-1]]" /><span class="im-hidden"></span></a>'
.'</div>', 'frontendlist' => '<div id="manager">[[ loop ]][[ paginator ]]</div>')))
{
return;
}
// string append
$loop = '';
foreach($pagedata['itemkeys'] as $key)
{
// Renders the 'loop' template to string concatenation by replacing placeholders
$loop .= $manager->paint('loop', array('loop-thumb-1' => $items[$key]['loop-thumb-1'],
'page' => $pagedata['viewpage'], 'slug' => $items[$key]['slug']));
}
/* If we want to split our item data across several pages, for instance, with 'Previous/Next'
links, for this, we can use already existing default templates. We then call the paginator()
method in a controller action. This method gets passed the default paginator templates by
calling the getTplKit('paginator') before paint() renders the template to output */
echo $manager->paint('frontendlist', array('loop' => $loop,
'paginator' => $manager->paginator(ImModel::getTplKit('paginator'))));
?>
PHP Code:
<?php
$manager = new ImController();
$id = isset($_GET['item']) ? $_GET['item'] : '';
/* This method returns an array which contains detailed data of a single item
specified by item ID */
if(!$itemdata = $manager->runModelMethod('get_item_data', $id))
{
return;
}
$path = ImModel::getProp('paths', 'siteurl').ITEMUPLOADDIR;
// templates as files for demonstration
if(!$manager->tplRegister(array('details' =>
GSPLUGINPATH.'imanager/tpl/frontend/page.details.tpl',
'detailsloop' => GSPLUGINPATH.'imanager/tpl/frontend/page.details.loop.tpl')))
{
return;
}
$loop = '';
$preload = array();
for($i=1; $i < 6; $i++) {
if(!empty($itemdata->{'loop-thumb-'.$i})) {
$loop .= $manager->paint('detailsloop', array('count' => $i));
}
if(!empty($itemdata->{'image-'.$i})) {
$preload[]= '"[[image-'.$i.']]"';
}
}
$preload = implode(',', $preload);
$manager->tplRegister(array('currloop' => $loop));
$loop = $manager->paint('currloop', array(
'image-1' => $path.basename($itemdata->{'image-1'}),
'image-2' => $path.basename($itemdata->{'image-2'}),
'image-3' => $path.basename($itemdata->{'image-3'}),
'image-4' => $path.basename($itemdata->{'image-4'}),
'image-5' => $path.basename($itemdata->{'image-5'}),
'image-6' => $path.basename($itemdata->{'image-6'}),
'loop-thumb-1' => $path.basename($itemdata->{'loop-thumb-1'}),
'loop-thumb-2' => $path.basename($itemdata->{'loop-thumb-2'}),
'loop-thumb-3' => $path.basename($itemdata->{'loop-thumb-3'}),
'loop-thumb-4' => $path.basename($itemdata->{'loop-thumb-4'}),
'loop-thumb-5' => $path.basename($itemdata->{'loop-thumb-5'}),
'loop-thumb-6' => $path.basename($itemdata->{'loop-thumb-6'}))
);
echo $manager->paint('details', array(
'preload' => $preload,
'image-1' => $path.basename($itemdata->{'image-1'}),
'image-2' => $path.basename($itemdata->{'image-2'}),
'image-3' => $path.basename($itemdata->{'image-3'}),
'image-4' => $path.basename($itemdata->{'image-4'}),
'image-5' => $path.basename($itemdata->{'image-5'}),
'image-6' => $path.basename($itemdata->{'image-6'}),
'title' => stripslashes(html_entity_decode($itemdata->{'title'}, ENT_QUOTES, 'UTF-8')),
'description' => stripslashes(html_entity_decode($itemdata->{'description'}, ENT_QUOTES, 'UTF-8')),
'loop-tpl' => $loop)
);
?>