mirror of
https://github.com/bcit-ci/CodeIgniter.git
synced 2025-02-20 11:13:29 +08: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.
|
||||
|
||||
The helper is tested but not yet fully. And I will add more examples...
|
||||
|
||||
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]
|
||||
|
||||
@ -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.
|
||||
|
||||
[b][i]array[/i] $options[/b]
|
||||
Accepts the following values, which are all set to empty (0, '' or array()) by default.
|
||||
[list]
|
||||
[item]int level
|
||||
Default op 0, houdt het niveau bij[/item]
|
||||
[item]string indent
|
||||
Default op niks, vervangt {INDENT} met $options['level'] keer het aantal indents[/item]
|
||||
[item]string link
|
||||
Default op niks, zet deze variabele tussen alle items[/item]
|
||||
[item]array ignore
|
||||
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]
|
||||
[item]string template_head
|
||||
Default op niks, gaat een sublijst voor[/item]
|
||||
[item]string template_foot
|
||||
Default op niks, sluit een sublijst af[/item]
|
||||
[item]array alternate
|
||||
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]
|
||||
[item]array functions
|
||||
Default op leeg, vraagt om een array van 2 plaatsige arrays: array(object, method), vervangt {METHOD} met de methode naam[/item]
|
||||
[/list]
|
||||
Accepts the following values:
|
||||
- [i]int[/i] level (defaults to 0)
|
||||
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...
|
||||
- [i]string[/i] indent (defaults to '')
|
||||
Accepts a string that will be added $option['level'] times where you put {INDENT}
|
||||
- [i]string[/i] link (defaults to '')
|
||||
Will be added between items, but not before the first or after the last.
|
||||
- [i]array[/i] ignore (defaults to array())
|
||||
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).
|
||||
- [i]string[/i] template_head (defaults to '')
|
||||
Will be added before each list (for example <ul>), can be ignored for the top list.
|
||||
- [i]string[/i] template_foot (defaults to '')
|
||||
Will be added after each list (for example </ul>), can be ignored for the top list.
|
||||
- [i]array[/i] alternate (defaults to array())
|
||||
Takes multiple values that will alternate to replace the {ALTERNATE} tag.
|
||||
- [i]array[/i] 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}
|
||||
|
||||
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]<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user