Super Ultra Mega Dynamic Menu Post - all gurus and no gurus invited |
[eluser]MEM[/eluser]
Ok... I'm really trying hard this one. After this: http://ellislab.com/forums/viewthread/97373/ and this: http://ellislab.com/forums/viewthread/127749/ and this: http://ellislab.com/forums/viewthread/128046/ and this: http://ellislab.com/forums/viewthread/128272/ and this: http://ellislab.com/forums/viewthread/128561/ and the last one: http://ellislab.com/forums/viewthread/132366/ BrianDhall, Jedd, Phil Sturgeon... I'm dying. X.X But, above all, confused. Before I was unable, when the users clicked on a link, to display all, child and parents at once. Now, I CAN (yes we can...) do that. Based on the choices made on the MAIN MENU I'm now able to display the correct parent and child elements of the SUBCATEGORIES MENU. No issue there. All works. HOWEVER, once I click on a link on that submenu, all falls apart. Have a look on my controller: Code: function seccao($id) I realise that my SUBCATEGORIES MENU cannot change the value of the third segment ID. If I do that, the query on my model will return nothing, hence, I will see no menu displayed on the page. So, the third segment shouldn't be changed. I thought, ok... I need to keep the third segment intact in order to keep seeing the menu on the page, so, what about adding a new segment? However, I presume, we cannot just add segments like this on a CI application, and I'm telling this, because, if I do: something like: Code: echo anchor(current_url().’/’.$subcategorias[‘id_cat’].’/’,$subcategorias[‘nome_cat’]); I'm unable to make them work properly, because, if we click several times on one SUBCATEGORY MENU ITEM, we will always get, the current URI + the id. So, if you click like 10 times, you will end up with something like this: http://www.site.com/c_categoria/seccao/1.../8/7/7/7/8 instead of simply: http://www.site.com/c_categoria/seccao/1/8/ My question is: How can we, logicically and structurally, add a section on our URI without having this unlimited section issue? So that, when we click on a SUBCATEGORY MENU ITEM, we get: http://www.site.com/c_categoria/seccao/1/8/ when we click on another SUBCATEGORY MENU ITEM we get: http://www.site.com/c_categoria/seccao/1/4/ when we click on a CHILD on that SUBCATEGORY MENU ITEM, we get: http://www.site.com/c_categoria/seccao/1/4/6/ Please... something... Regards, Márcio ps- I'm really sorry for all the past separate posts, they were arriving with my doubts. I've now put them all together on this one. Once again, sorry for that.
[eluser]jedd[/eluser]
Okay.. I'm not keen on trawling through all those past posts again, so forgive me if I also end up repeating a few things. Can you clarify. When you compare the two scenarios: Quote:I'm unable to make them work properly, because, if we click several times on one SUBCATEGORY MENU ITEM, we will always get, the current URI + the id. So, if you click like 10 times, you will end up with something like this: What is the first '1' there designating? You say that you can't change the value of the third segment ID, but I'm not really sure why you have that limitation. The nature of sub/parent categories navigation - at least for me - is that you change where *you* are, as you navigate, and then work out what's up and down from your new position. There's no need to keep old context information - say, your previous category - because it becomes irrelevant as soon as you land on the new page. Perhaps if you rewrite your URL generations to be base_url + current controller + current method + ID. This is pretty much what I do for a place-controller, where I have a tree structure I'm navigating through. The ID immediately defines context for me - and I can identify the sole parent, and all children, and peers, from that one piece of data.
[eluser]MEM[/eluser]
Hello Jedd, thanks for your reply. I will try to not loose the focus here, so I will try to split this is shorter questions: [quote author="jedd" date="1255819554"] What is the first '1' there designating? [/quote] It designates a category ID. (for each category I'm having a menu of subcategories that will be based on that category ID that is passing on the URI segment). [quote author="jedd" date="1255819554"] You say that you can't change the value of the third segment ID, but I'm not really sure why you have that limitation. [/quote] I can change, however, if I do it, I will be unable to see the subcategory menu. (because the subcategory menu gets generated based on the URI passed on the third segment. (the $id). Please have a look on the following link: http://www.nuvemk.com/c_categoria/seccao/1 The vertical not formatted ul list, constitutes the MAIN CATEGORY MENU. When you click on one of the MAIN CATEGORY MENU ITEMS, you will see, below, other links. Those links, constitutes a SUB CATEGORY MENU based on the ID passed, when you click on the links of the menu above. [quote author="jedd" date="1255819554"] Perhaps if you rewrite your URL generations to be base_url + current controller + current method + ID. [/quote] I have a base url, + current controller (c_categoria) + current method(seccao) + id (passed on the 3rd segment), I believe. Here is an example of a link on the subcategory menu, having all: echo anchor( uri_string() . '/' . $subcategorias['id_cat'] . '/',$subcategorias['nome_cat']); Please ask as much as you wish, I will be more then glad to answer, in order to solve this. Thanks a lot, Márcio
[eluser]MEM[/eluser]
Ok... Quote:I have a base url, + current controller (c_categoria) + current method(seccao) + id (passed on the 3rd segment), I believe. Here is an example of a link on the subcategory menu, having all: I was NOT having the base_url obviously, I was having the current URL, and that have made all the difference. Current url doesn't fit here. I will try with base_url instead, as you have suggested. However, I believe I cannot use the equation: base_url + current controller + current method + ID., simply because, if I do that, I will change the "sacred" third segment, and that will disable the possibility of seem the menu that was there based on the 3rd segment ID. You would reply that that is not important because, we can still retrieve that menu based on our current location, but I just don't see how. So, I will try to do the same steps but, this time, I will use the base_url instead. In the meanwhile, please, any efforts to help me out finish this, are more then welcome... :S Regards, Márcio
[eluser]jedd[/eluser]
[quote author="MEM" date="1255832847"] I was NOT having the base_url obviously, I was having the current URL, and that have made all the difference. Current url doesn't fit here. I will try with base_url instead, as you have suggested. [/quote] Ah, yes, current_url() would indeed grow things as you saw. I think you're definitely going to have to re-build the URL on each trip, but that's not so tricky - and could be shifted into a MY_Controller function if a pro forma would be useful often enough. Quote:However, I believe I cannot use the equation: base_url + current controller + current method + ID., simply because, if I do that, I will change the "sacred" third segment ... Can't you just keep the sacred third segment? Flashdata is an obvious, if inelegant way of doing this, or better yet pulling it out of the current URL with an rsegment() call, etc. Quote:You would reply that that is not important because, we can still retrieve that menu based on our current location, but I just don't see how. IFF sub-categories have one parent and one parent only, then it's painfully easy - you have a model method, say get_parent($sub_cat_id), that returns this information. This is the approach I use, but I'm making database calls like they're going out of fashion. ![]()
[eluser]MEM[/eluser]
Hello again, I have create the links using the base_url + controller/method + parent_id_cat + id_cat equation. Apparently it seems that with this change, I'm now able to display all the menu items, even when we change the URI: Code: echo anchor( base_url() . 'c_categoria/seccao/' . $subcategorias['parent_id_cat'] . '/' . $subcategorias['id_cat'] . '/',$subcategorias['nome_cat']); I'm still not sure if this will work with the subcategories Childs elements down on this hieratic multidimensional array returned... I will try this with the subcategories child elements tomorrow, and I will see what will arrive. Note: the above link as been updated, so the issue reported on the previous post can't be seen anymore. Update: note2: Jedd, the above was written before I see your previous post, so, let the add that: What is easy for you, isn't, by any standards, easy for me. Let's say it will be more like: what will be dreadful easy for you, will be hard enough for me. ![]() Still, I will try the solution by using the parent_cat_id and the id_cat on the links URL construction, and see if it will work with the child elements as well, if it does, I believe I'm on the right track (or, at the best track possible), if it doesn't, then I probably need to ask you some questions about the above solutions provided by you on this last post. Regards once again, and really, thank you for your feedback, Márcio
[eluser]InsiteFX[/eluser]
Take out the base_url() and only include the segments! Enjoy InsiteFX
[eluser]MEM[/eluser]
Of course! It seems a great idea. ![]() About the show hide of the buttons, I'm seeing here and there that, for accomplish something like this we could use only CSS or CSS+Javascript. I more or less got the concept but there is something that bogus me: I want to display the child elements when the parent is clicked. That's for sure. But, I'd like also to display the child elements, when anyone navigates directly trough the URL. (for an external link for example) ie. www.mysite.com/c_category/categoryID/subcategoryID How do you normally solve this, is order to allow access to hidden parts of the menu, not only when the user clicks, but also, when some URL is on the address bar? On the server side, using CI libraries? Or more on the js side of things? Thanks in advance, Márcio
[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. ![]() 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) Thanks a lot in advance, Márcio
[eluser]jedd[/eluser]
[quote author="MEM" date="1256760365"] 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. [/quote] As long as these are organic herbicides, I'll be happy to help (I'm a permaculturist - so naturally wary ![]() The reason you're losing the parent, is because you're only displaying the new entity + new entity's children. Quote:Can I have your help in order to understand how can I recursively build the URI segments? By recursively build the URI segments, do you mean the model / database side that pulls out the information, or actually generating a URL that provides the full parentage? If you mean the URL thing, I'd suggest you don't go down that path - it'll get ugly. Any single ID you get on the URL can be used to identify WHERE in the hierarchy you are - and you can then have model calls that look up parentage, as well as children. On my site database that I sent you the URL for, I show all the parentage (each item has a single parent, so I just recursively head upwards until I find a parent_id of 0) and I show only the immediate children. The parentage information is used to give the user some context for what they're looking at. If you don't give them that information, then it will be like you have shown above - the user sees Fitofármacos, but then loses it when they go into Herbicidas - and they don't have anything on the screen to indicate how to get back up to Fitofármacos, or where Herbicidas fits into the overall structure. How about something like this: visual information to the user (view stuff) has a prefix like this: Top | Fitofármacos | Herbicidas - children : herb1, herb2, herb3 -- where Herbicidas (in this case) is bold/larger/not-a-URL-link but everything else is a link database functions (model stuff): find_parents ( $thing ) - returns an array of parentage for the $thing find_children ( $thing ) - returns an array of children of $thing Those two arrays would be enough to create the view I described. Would that approach kind of get you where you want to go? |
Welcome Guest, Not a member yet? Register Sign In |