|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
We can do it in different ways. Configuration data are sent by POST.
Some of them should be parsed before saving to file. Perhaps, I will use var_export(). However, how to do it best? 1. Without a class / function. Fields names have no prefix and are equal to $cfg array's indexes. <input name="option_name" /> In every file of options form (e.g. main options, content options, e- mail...) you insert: if(file_put_contents('cfg/file_name.php', var_export($_POST,1), 2)) { ... } If you must parse some data: $_POST['data'] = Clean($_POST['data']); 2. With a class / function. Fields names may contain prefix (e.g. u_). <input name="u_option_name" /> Saving data: $o = new Config(...); $o -> add('option_name', 'int'); $o -> add('option_name'); $o -> save('file_name'); //or: $o = null; 3. Method 2 with dynamic options forms: $o = new Config(...); $o -> add('option_name', 'int', 50); No, it isn't good example. You can have textarea fields (even with editor), text, radio (more choices for 1 option), checkbox, select (with <option>s which can be generated by other functions, e.g. category list). 4. Array (more code): $array = array( 'opt1' => (int) $_POST['u_option'] ); The main configuration page has above 30 options. However, the method with $o -> add(...) may be slower. What do you think about it? Which choice is the best or maybe you have other solutions? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
WebCM wrote:
> We can do it in different ways. Configuration data are sent by POST. > Some of them should be parsed before saving to file. > > Perhaps, I will use var_export(). However, how to do it best? > > 1. Without a class / function. > Fields names have no prefix and are equal to $cfg array's indexes. > <input name="option_name" /> > > In every file of options form (e.g. main options, content options, e- > mail...) you insert: > if(file_put_contents('cfg/file_name.php', var_export($_POST,1), 2)) > { > ... > } > > If you must parse some data: > $_POST['data'] = Clean($_POST['data']); > > 2. With a class / function. > Fields names may contain prefix (e.g. u_). > <input name="u_option_name" /> > > Saving data: > $o = new Config(...); > $o -> add('option_name', 'int'); > $o -> add('option_name'); > $o -> save('file_name'); //or: $o = null; > > 3. Method 2 with dynamic options forms: > > $o = new Config(...); > $o -> add('option_name', 'int', 50); > > No, it isn't good example. You can have textarea fields (even with > editor), text, radio (more choices for 1 option), checkbox, select > (with <option>s which can be generated by other functions, e.g. > category list). > > 4. Array (more code): > > $array = array( > 'opt1' => (int) $_POST['u_option'] > ); > > The main configuration page has above 30 options. However, the method > with $o -> add(...) may be slower. What do you think about it? Which > choice is the best or maybe you have other solutions? > Personally, I'd place it in a database. But then I like databases :-) -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
![]() |
| Outils de la discussion | |
|
|