COMBO Page... kinda
5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 25, 2014 (RSS)
By Toledoh - March 19, 2014
Hey Guys,
I would like to produce a page similar to the combo page layout that generated via the code generator, however rather than a "title" as the side menu, and the "Detail record" to the right, I would like a "Category" to the left and a sub-list to the right.
ie. I have a table of records, each record has a "title", "category" (which is a list) and other details. Click on a category, and get all the items with that category selected. And show the selected category via the "<?php if ($isSelected) { print "<b>"; } ?>".
Is that easily achievable?
Tim (toledoh.com.au)
By Daryl - March 24, 2014
Hi Tim,
Yes, we can easily achieve that by replacing the left list with the category list from the records and add a link parameter, i.e. ?category=1 and use the parameter value to determine which records will be displayed on the right list.
Here's an example of what I would do:
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('W:/test/htdocs/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records from 'products_listing'
list($products_listingRecords, $products_listingMetaData) = getRecords(array(
'tableName' => 'products_listing',
'loadUploads' => true,
'allowSearch' => false,
));
// get the list of categories as array wherein the array key is the category value, and array value is the category label
// $productCategoriesValuesToLabels will be used for the left category list
$productCategoriesValuesToLabels = array_combine(array_pluck($products_listingRecords, 'category'), array_pluck($products_listingRecords, 'category:label'));
// $productsListsRecords will be used for the right sub-list
$productsListsRecords = array();
if (@$_REQUEST['category']){
$productsListsRecords = array_groupBy($products_listingRecords, 'category', true);
$productsListsRecords = @$productsRecords[$_REQUEST['category']];
}
?>
<!--left category list-->
<?php if (@$productCategoriesValuesToLabels ): ?>
<?php foreach ($productCategoriesValuesToLabels as $value => $label): ?>
<a hef="?category=<?php echo htmlspecialchars($value); ?>"><?php echo htmlspecialchars($label); ?></a>
<?php endforeach; ?>
<?php endif; ?>
<!--right category list-->
<?php if (@$productsListsRecords): ?>
<?php foreach ($productsListsRecords as $product): ?>
<a hef="<?php echo htmlspecialchars($product['_link']); ?>"><?php echo htmlspecialchars($product['title']); ?></a>
<?php endforeach; ?>
<?php endif; ?>
Hope this helps!
Cheers,
PHP Programmer - interactivetools.com
By Toledoh - March 24, 2014
Thanks Daryl - but I'm not getting anything displayed for the right sub list...
Tim (toledoh.com.au)
By Daryl - March 25, 2014
Hi Tim,
Can you please try to update the block of codes below and let me know if that fixes it? The changes are colored blue:
// $productsListsRecords will be used for the right sub-list
$productsListsRecords = array();
if (@$_REQUEST['category']){
$productsListsRecords = array_groupBy($products_listingRecords, 'category', true);
$productsListsRecords = @$productsListsRecords[$_REQUEST['category']];
}
Thanks,
PHP Programmer - interactivetools.com