Generic list generator helper with templates (ul, ol, select box, etc.) |
[eluser]hugle[/eluser]
[quote author="Jelmer" date="1226817283"]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). UPDATE 11/16: Some improvements I'm thinking about - 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 certain keys too (like: some_method[arg1, -key_name-]) ANOTHER UPDATE 11/16: Some bugfixes and these improvements: - Remove any leftover tags at the end - 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) Any suggestions or improvements are welcome![/quote] Nice contribution Jelmer. I'm going to use it in near future I think. Good luck! |
Welcome Guest, Not a member yet? Register Sign In |