Generic list generator helper with templates (ul, ol, select box, etc.) |
[eluser]Jelmer[/eluser]
The code and explanation are in the wiki: http://codeigniter.com/wiki/Generatic_List_Generator/ If the ul(), ol() and form_dropdown() aren't powerfull enough for you, this might do the trick. Check out the wiki post for some explanation about how it works and what it can do. I will write up some more complex examples to better show its usefullness. UPDATE november 16: I added some examples below I wrote it just now and I'm still testing it but it already created values for Script.aculo.us inPlaceCollectionEditor, a selectbox and multiple nested lists without any problem. What can be done better There's a couple of things that can possibly be done a lot better, like the alternation of values which doesn't continue within/after a nested set. Within a nested set it starts from the begining and after it continues with the value the parent had. Also, the helper will quite happily produce non-valid code if you structure your arrays wrong - bot I don't really consider that a bug. For instance array(1,2,3,array('a','b') would produce non-valid code and array(1,2,3=>array('a','b') would produce valid code (the sublist enclosed within the LI of the '3'-node). Some improvements I'm thinking about (last update: 12/10) - Improve the functions within classes recognition for classes which aren't instantiated on their own name within CI - Add arguments to the 'functions' options, so values can be passed through brackets like in the form_validation (for instance: some_method[arg1, arg2]) and maybe allow for passing the value of keys too by prefixing those with itemvalue_ (like: some_method[arg1, itemvalue_keyname]) - Prevent double $option['link'] to be added because of ignore values (now solved by removing a double found with a single at the bottom of the function) - Add selection option Some bugfixes and these improvements (last update: 12/10) - Bugfix: moved the foreach loop for external functions within and outside classes, which now detects if the expected class is the current controller. Though it still wouldn’t handle a class correctly for which the classname and the variablename within CI aren’t the same. (for example: a library “Example” would be instantiated on $this->example) - Bugfix: added a str_replace at the end that replaces any double added $option[‘link’], should be prevented but don’t have the time to figure out a decent patch. (update: 11/20) - Remove any leftover tags at the end (update: 11/16) - Replace the preg_replace() with str_replace() where possible (which is nearly everywhere, I just used preg_replace because I'm used to it, not because it's needed) (update: 11/16) Any suggestions or improvements are welcome! |
Welcome Guest, Not a member yet? Register Sign In |