Welcome Guest, Not a member yet? Register   Sign In
Interesting talk you guys might enjoy regarding MVC and validation
#1

[eluser]Majd Taby[/eluser]
http://jtaby.tumblr.com/post/95004488/an...lti-tiered
#2

[eluser]dmyers[/eluser]
While I know CI validates in the Controller via form. I personally validate in the model. because you maybe adding data to the model in many different controllers. putting it in the model I only need to add it once. The controller sends in the data to the model. If it's bad it returns false and the error(s) "array" contains the errors

I also added jquery to my forms to send the data back to the "check for errors" controller so you never actually leave the page and the errors are displayed as a dialog. if the ajax call says everything is good it then submits the form. which for safety is validated 1 last time (which should pass unless somebody is monkeying around).

comments welcome.
#3

[eluser]Majd Taby[/eluser]
I agree (as I said in the convo)
#4

[eluser]Mike Ryan[/eluser]
Just FYI... light and dark blue text on a dark blue background is not easiest thing to read! :-)
#5

[eluser]Phil Sturgeon[/eluser]
If the data for an entity will always be the same then that is fine, however I often use different validation for front and backends. I suppose this you could have front and backend methods in the model and validate there?
#6

[eluser]dmyers[/eluser]
Well when I build my models I include every field validation requirement in the model. If for some reason that changes on a form (ie frontend vs backend) I have a validate_only method for my model parent object/class. I pass in ONLY the field names of what needs to be validated. If for some reason it's not a full validation. Again to make it easy I only need to call a single function to turn on/off certain field validations.

Oh ya and since I use ajax to post the information back to the server for validation I get both client side and server side validation from the exact same code! -- of course again it's only written once in the model! Does that make me lazy?
#7

[eluser]kyleect[/eluser]
[quote author="dmyers" date="1239473760"]Well when I build my models I include every field validation requirement in the model. If for some reason that changes on a form (ie frontend vs backend) I have a validate_only method for my model parent object/class. I pass in ONLY the field names of what needs to be validated. If for some reason it's not a full validation. Again to make it easy I only need to call a single function to turn on/off certain field validations.

Oh ya and since I use ajax to post the information back to the server for validation I get both client side and server side validation from the exact same code! -- of course again it's only written once in the model! Does that make me lazy?[/quote]

Are you using a custom library for validation in the model? Does stock library only work in the controller?
#8

[eluser]dmyers[/eluser]
Yes, I am. I wrote my own CRUD+ (create, read, update, delete) parent model class. Got ideas from a few different PDO, Active Record, KISSMVC, CI DataMapper, etc...

I would post it but I wanted to refactor a bit more and continue to test it in a number of applications I have been writing to know it's ready for public release.

I read somewhere you can "force feed" the built in one with your own data but havn't looked into that. I got a lot from CI DataMapper (Thank's guys)




Theme © iAndrew 2016 - Forum software by © MyBB