Welcome Guest, Not a member yet? Register   Sign In
how do you deal with your variables?
#1

[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
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB