Welcome Guest, Not a member yet? Register   Sign In
sub-categories and sub-subcategories on a associative array with CI
#8

[eluser]BrianDHall[/eluser]
Just incase it might be useful, I found and yanked out how I did it on the mentioned site. Obviously there are some custom functions, but none of them are very fancy, just basic database queries.

One thing though, if it makes you feel any better you are actually tackling something extremely hard that many systems handle simply by not supporting it. Joomla, for instance - their integrated category/menu system allows Categories, Subcategories...and that's all. If you want more, tough.

I believe the technical name for this is an unlimited nested taxonomical menu system, or something like that. It's considered a big deal, so don't feel bad that it's really hard. I dreaded making this work as it was one of the reasons I tossed Joomla aside to start with.

Anyhoo, just as food for thought incase it's useful, here's how I did it. I did it in a view actually, to tell you how mess it was - but damned if I'm going to do anything about it, it works and I'm willing to accept that Wink

The cellcount is because the page will break if there are too many categories, the table will get so wide that the screen goes screwy. The parts about active category image is to make the chosen upper level categories be highlighted, and to give the "open safe" image on my page instead of the closed, 'inactive' safe icon.

It's by no means the most elegant ways of doing it and I'm still not sure I understand why I did while($parent)...but again, it worked and I'm leaving that dog alone.

Hope it's useful!

Code:
<?php

$cellcount = 0;

foreach ($categories as $category)
{
    $cellcount = $cellcount + 1;

    // Control amount of cells per row so as not to break browsers width.
    if (in_array($category['uricode'], $urisegments) )
    {
        // Set active category image.
        $imgurl = site_url() . 'images/stories/home-on.png';
        $cell = ' bgcolor="#006600"';
    }
    else
    {
        $imgurl = site_url() . 'images/stories/home.png';
        $cell = '';
    }
    
    $parenturi = '';
    
    if ($category['ParentCategoryID'])
    {
        $parent = $this->Categories->getCategoryByID($category['ParentCategoryID']);
        
        while ($parent)
        {
            $parenturi = $parent['uricode'] . $parenturi;
            
            if ($parent['ParentCategoryID'])
            {
                $parent = $this->Categories->getCategoryByID($parent['ParentCategoryID']);
                $parenturi = '/' . $parenturi;
            }
            else
            {
                $parent = false;
            }
            
        }
    }

    echo '<td width="50"' . $cell . '><a href="' . site_url('pensacola_florida_discounts/coupons_by_category/' . $parenturi . '/' . $category['uricode']) . '" title="' . $category['CategoryPageTitle'] . '" class="submenu"><img src="' . $imgurl . '" alt="' . $category['CategoryPageTitle'] . '" title="' . $category['CategoryPageTitle'] . '" height="45" width="45" /></a></td><td width="65"' . $cell . '><a href="' . site_url('pensacola_florida_discounts/coupons_by_category/' . $parenturi . '/' . $category['uricode']) . '" title="' . $category['CategoryPageTitle'] . '" class="submenu">' . $category['CategoryMenuText'] . '&nbsp;</a></td>
    ';

    if ($cellcount >= 8)
    {
        echo '<td>&nbsp;</td></tr><tr>';
        $cellcount = 0;
    }

}

?&gt;


Messages In This Thread
sub-categories and sub-subcategories on a associative array with CI - by El Forum - 09-04-2009, 06:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB