Welcome Guest, Not a member yet? Register   Sign In
Super Ultra Mega Dynamic Menu Post - all gurus and no gurus invited
#9

[eluser]MEM[/eluser]
Ok, let's forget about the last post. I'm now able to partially, show/hide elements and partially, change the URL as well.
But NOW, and only NOW, I start do understand why some of you have coursed recursion. Wink

Please have a look here:
http://www.nuvemk.com/c_categoria/seccao/1

When we click on "Fitofármacos", I can display the correspondent children! This is great! And I'm really happy!

When we click on Fitofármacos children - "Herbicidas", I was expecting to have returned Herbicidas childs, without losing the Fitofármacos menu item.

The reason I'm loosing him, I suppose, it's because the URI is not properly generated by the function responsible to parse a menu.

Notice that, on the link posted above:
If you click on fitofármacos and then click on herbicidas, the expected URL should be:
http://www.nuvemk.com/c_categoria/seccao/1/6/9/

but I'm getting this instead:
http://www.nuvemk.com/c_categoria/seccao/6/9/

If we try to navigate deeply, and inside Herbicidas we click on "Herbicidas A", we are expecting an URL like so:
http://www.nuvemk.com/c_categoria/seccao/1/6/9/27/

But we are getting this instead:
http://www.nuvemk.com/c_categoria/seccao/9/27/


Can I have your help in order to understand how can I recursively build the URI segments?

Here is the actual code:
Code:
function parse_into_menu($arrMenu,$strParentIdKey,$strChildKey,$strNameKey,$strIdKey,$intRunner=0)
{
    
     //allow the use of uri->segment inside this function:
     $CI =& get_instance();
    
    //grab the last segment
      $strLastSegment = end($CI->uri->segment_array());  

    $strNL = "\n";
    
    
    foreach ($arrMenu as $subcategorias)
    {
        echo anchor( base_url() . 'c_categoria/seccao/' . $subcategorias[$strParentIdKey] . '/' . $subcategorias[$strIdKey] . '/',$subcategorias[$strNameKey]),$strNL;
        
        if(!empty($subcategorias[$strChildKey]))
        {
            if ($subcategorias[$strIdKey] === $strLastSegment)
            {
                       parse_into_menu($subcategorias[$strChildKey],$strParentIdKey,$strChildKey,$strNameKey,$strIdKey,$intRunner+1);
            }
            
        }
            
    }
    
}

parse_into_menu($menucategorias,'parent_id_cat','children','nome_cat','id_cat');



Thanks a lot in advance,
Márcio


Messages In This Thread
Super Ultra Mega Dynamic Menu Post - all gurus and no gurus invited - by El Forum - 10-28-2009, 09:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB