...

World Wide Web Server 2012-07-04 16:05:06 -07:00
parent 7760aa84ec
commit 0796cd85b0

@ -1,5 +1,7 @@
After having rewritten the same function for different controllers and only changing minor things within the function itself, I finally got round to creating a helperfunction that does the trick. This helper should be able to generate just about any list you might want, whether is be a UL, OL, <select>/<option> or a Script.aculo.us inPlaceCollectionEditor list. After having rewritten the same function for different controllers and only changing minor things within the function itself, I finally got round to creating a helperfunction that does the trick. This helper should be able to generate just about any list you might want, whether is be a UL, OL, <select>/<option> or a Script.aculo.us inPlaceCollectionEditor list.
The helper is tested but not yet fully. And I will add more examples...
This helper contains one function: This helper contains one function:
[b][i]string[/i] generate_list([i]array/object[/i] $resource, [i]array[/i] $options, [i]string[/i] $template)[/b] [b][i]string[/i] generate_list([i]array/object[/i] $resource, [i]array[/i] $options, [i]string[/i] $template)[/b]
@ -7,26 +9,38 @@ This helper contains one function:
Gets either an array or an object and uses it as the data for its list, it can contain arrays which it will either accept as an associative array (to create a single entry with multiple parameters) or just multiple values to create a sublist which will be nested. Gets either an array or an object and uses it as the data for its list, it can contain arrays which it will either accept as an associative array (to create a single entry with multiple parameters) or just multiple values to create a sublist which will be nested.
[b][i]array[/i] $options[/b] [b][i]array[/i] $options[/b]
Accepts the following values, which are all set to empty (0, '' or array()) by default. Accepts the following values:
[list] - [i]int[/i] level (defaults to 0)
[item]int level Keeps track of the level, the toplist gets 0 and a nested list gets 1, a list nested in the nested list gets 2, etc...
Default op 0, houdt het niveau bij[/item] - [i]string[/i] indent (defaults to '')
[item]string indent Accepts a string that will be added $option['level'] times where you put {INDENT}
Default op niks, vervangt {INDENT} met $options['level'] keer het aantal indents[/item] - [i]string[/i] link (defaults to '')
[item]string link Will be added between items, but not before the first or after the last.
Default op niks, zet deze variabele tussen alle items[/item] - [i]array[/i] ignore (defaults to array())
[item]array ignore Take an associated array where the values may be arrays. It checks each key/value in the $resource against this list if it is set and ignores any key/value(s) that match (which also ignores the children of this node).
Default op leeg, negeert ieder item waar de key & value overeen komen met de key/value in de ignore array (als de value in de ignore lijst een array is wordt iedere waarde gecheckt)[/item] - [i]string[/i] template_head (defaults to '')
[item]string template_head Will be added before each list (for example <ul>), can be ignored for the top list.
Default op niks, gaat een sublijst voor[/item] - [i]string[/i] template_foot (defaults to '')
[item]string template_foot Will be added after each list (for example </ul>), can be ignored for the top list.
Default op niks, sluit een sublijst af[/item] - [i]array[/i] alternate (defaults to array())
[item]array alternate Takes multiple values that will alternate to replace the {ALTERNATE} tag.
Default op leeg, geeft rij om rij (om rij, om rij, etc...) een waarde mee alternerend aan de hand van het aantal waarden en vervang {ALTERNATE}[/item] - [i]array[/i] functions
[item]array functions Takes an array that contains array with 2 values like this [i]array(method_name, object_name)[/i], if there's no such method in the object or the object isn't set it also checks the general namespace for a function by the method_name. When called it passes the level and the number to the called function. It replaces a tag by the function name uppercase: {METHOD_NAME}
Default op leeg, vraagt om een array van 2 plaatsige arrays: array(object, method), vervangt {METHOD} met de methode naam[/item]
[/list]
The following example:
[code]$this->load->helper('generate_list');
$resource_test = array(array('something'=>array('a','b','c')),'test','and something else');
$options = array(
'template_head'=>'<ul>',
'template_foot'=>'</ul>',
'alternate'=>array('color: blue;', 'color: red;')
);
echo generate_list($resource_test, $options, '<li style="{ALTERNATE}">{CONTENT}</li>');[/code]
Will generate:
[code]<ul><li style="color: red;">something</li><ul><li style="color: red;">a</li><li style="color: blue;">b</li><li style="color: red;">c</li></ul><li style="color: blue;">test</li><li style="color: red;">and something else</li></ul>[/code]
[code]&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); [code]&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');