(2016-04-17, 00:57:40)nihaha Wrote:Code:<ul class="item-list">
<?php
foreach($itemAccessor->items as $item) {
echo '<li>'. $item->name . '</li>';
}
?>
</ul>
Ok. I just wanted to know how you pass your item and category data on the function that should display item details. But I see nothing in your example.
To show the data of a specific item you first have to send the "slug" or "id" of the item's category. You should also pass the item's "id" or "slug" (when you are using slug field), so your foreach loop might then look like this:
Code:
foreach($items as $item) {
echo '<p><a href="catalog/'.$category->slug.'/?item="'.$item->get('id').'" >'.$item->name.'</a></p>';
}
On the details page you will then receive the data you send:
Code:
// the $slug could be your category slug
$slug = get_page_slug(false);
if(!empty($slug) && !empty($_GET['item'])) {
$imanager = new IManager();
// Get the category id by the slug
$catAccessor = $imanager->getCategoryClass();
$categoryData = $catAccessor->getCategory("slug=$slug");
if(empty($categoryData)) die('Category Data was not found');
// get a single item by category-ID and item-ID
$itemsAccessor = $imanager->getItemClass();
$itemsAccessor->limitedInit($categoryData->get('id'), (int)$_GET['item']);
$item = $itemsAccessor->items[(int)$_GET['item']];
}
Now, you can use your $item object:
Code:
if(!empty($slug) && !empty($_GET['item'])) {
...
$item = $itemsAccessor->items[(int)$_GET['item']];
// To output item name
echo $item->name.'<br>';
// To output a field value
echo $item->fields->your_field_name->value.'<br>';
// etc
}