CodeIgniter Forums
how do you deal with your variables? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how do you deal with your variables? (/showthread.php?tid=2498)



how do you deal with your variables? - El Forum - 08-08-2007

[eluser]batteries[/eluser]
I don't mind passing variables around in a "procedural" fasion.. But, when dealing with a complex execution, i will use a more oop approach and set my data into the relevant model as private variables.

So my question, how do you guys do it? is there a best practice? For my current project i want to deal with my data exclusively in the oop way but i'm not sure if i should validate before i set the data to variables, or to set the data as soon as i get it..

Thanks


how do you deal with your variables? - El Forum - 08-08-2007

[eluser]Phil Sturgeon[/eluser]
A method I like is:

Quote:Set all rules in array.
Foreach array_keys(rules), define $field array using language->item($field)

Validate

if($validate->run)
output error
else:
output success message
endif

$entry = some_model->getFromID($entryID)

foreach array_key(rules)
$data[$field] = isset(validation->$field) ? validation->field : $entry[$field]
endforeach

And BAM! You got a really small controller with error checking and language features, REALLY few code and no big old lists.

Hope the psuedo code will do it, its late and cba writing in syntax.