![]() |
xml based navigation structure within CI - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: xml based navigation structure within CI (/showthread.php?tid=16504) |
xml based navigation structure within CI - El Forum - 03-09-2009 [eluser]codeamatic[/eluser] I am going to implement an xml based navigation structure into one of my CI websites. The problem isn't that I don't know how to code it, but I'm somewhat lost as to how to structure it within CI. Should this be a Library? Should I load the xml file from within this Library(if you in fact think it should be a library) or should I load it within my constructor? Since this navigation will be called on every page, should it be called from within my extended controllers constructor? It will essentially create all of the html markup necessary for the navigation. As mentioned before, I'm not looking for coding assistance, but more or less someone to point me in the right direction as to how I would/should implement into CI. Thanks in advance... xml based navigation structure within CI - El Forum - 03-09-2009 [eluser]xwero[/eluser] the xml file can be seen as data so you could put it in a model but i would make a plugin out of it based on the modification time of the xml file with following steps - does the cache file exist -> no -> create cache file - is the modification time equal to the time stored in the file name of the cache file -> no -> create file - output cache file To create the cache file you could use a CI view file or a template engine. I would do it this way to prevent going through all the steps to create the navigation each time a page loads. xml based navigation structure within CI - El Forum - 03-09-2009 [eluser]codeamatic[/eluser] I was wondering about caching. Will caching be affected by the fact that this navigation menu will have to look at the current uri and then determine what link to highlight (give a class attribute of "on")? So essentially, everytime the user goes to a new page, I will again have to determine what link to highlight before displaying... I was thinking more along the lines of loading the xml file into a multidimensional array once (until the xml has changed) and referencing this array during the navigation rendering process... xml based navigation structure within CI - El Forum - 03-09-2009 [eluser]codeamatic[/eluser] sorry, it looks like i mis-read what you were saying...I get exactly what you mean...thanks... xml based navigation structure within CI - El Forum - 03-09-2009 [eluser]xwero[/eluser] You can use the css technique where the body tag id/class is related to the navigation example. Of course this will produce a long list if you have many pages but you can build a css just for this when you create the cache file. The problem is how to add the right id/class to the body tag. you can hardcode the class/id in the method but then is xml as navigation configuration disregarded. Storing an array with url and class/id in a file to get the right one seems redundant but the only way to identify the current links in all situations. A javascript solution fetches the class/id from the navigation link when it's clicked and store it in a cookie and with php you read out the coockie. But then you have to add the class to all navigational links on your pages too. I think you should do some tests to see which solution has the fastest rendering and the flexibility you need. xml based navigation structure within CI - El Forum - 03-09-2009 [eluser]codeamatic[/eluser] My team has decided that since we need to identify the current links in all situations we will be storing the menu structure in an array. Despite it being redundant, unfortunately it seems the best way to achieve our goal. To get back to my very first question, now that we have decided to store the menu in an array how should we structure the methods/functions to manipulate said array? Model or Library? Should the array be stored as a config variable? Our client has minimal php experience so if we could get away with storing this array in a file of its own so he/she could update when necessary, that would be great. |