php - codeigniter - what if I don't have any model? -


it's first time i'm using php framework , have question regarding design pattern.

let's i'm trying build php app has contact page (which ask name, email address comment etc , once submitted use mail function send email admin). know view gonna be, use controller render view, should model? i'm not going load database or save database. in case should skip model?

the gritty details go in model. simple contact form has lots of gritty specific details: names of fields, specific validation rules, etc.

the controller boss - validate form! it not how validate it, , doesn't need details of each field in form. if form validates - controller calls next view. if not validate - controller shows form again , maybe passes specific error messages.

  • the validation details contact form - put in model.

  • the emailing of form: content of email, taking form values , putting email, email goes to, details of sending email - work model.

what gain us? when client calls in year , says - change text in email - won't hunting through bunch of controller code. @ model names , know go. separation of concerns not building - inevitable changes happen on time.

edit

yes business logic should in model. contact form business rules might - ask name , address - , require email address , phone number. validation rules fulfill business rules.

then 6 months later client calls , says - people don't requiring phone number - make email required. have put validation rules in model - therefore specific model needs change. controller not change @ all! , since separated form validation rules sending of email separate models - if make mistake when changing validation rule - less code through , debug.

the other way @ - how specific , 'granular' method? more specific is, further controller should be. controller methods should change because of changes business rules.

so when said controller orders "validate form" - meant controller calling validation method in model, , getting true or false, no matter changes happen form on time.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -