Welcome Guest, Not a member yet? Register   Sign In
Which method you prefer?fat model or thin model?
#1

(This post was last modified: 10-27-2015, 09:44 AM by arma7x. Edit Reason: Typo )

I'm have change my coding style from fat controller to thin controller & fat model in my latest project. It's really helps me reduce from repeating during same works. How you done your work using CI & which method you prefer?
Keep calm.
Reply
#2

My next project with CI will be done with truly anorexic controllers, a business logic model layer, a database model layer, and views that are (fingers crossed) free from php other than minimal echoing and simple loops. That is the plan.
Reply
#3

Definitely fat models, although I realise this practise is not set in stone.

When you've got a lot of business logic in your controllers although it helps because you don't have to keep switching to different php files it actually makes it more easier for bugs to creep in.

Let's say you have two controllers which do the same thing, you would have to make sure any business logic in each controller is identical. If you move all the business logic into the model you only have one place to look for potential bugs.

This may not seem like much on small apps but when you start using 10's if not 100's of controllers you soon realise the benefit.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#4

I prefer, thin controllers & fat models with business logic in libraries since they tend to need to work with 1 or more models at a time and it makes the code more reusable in multiple controllers and/or other libraries.

DMyers
Reply
#5

If a fat model is causing duplication of work/code, it would probably be worth splitting it up into multiple models and/or a library to reduce the duplication. I can't really think of a situation in which moving any of the code into controllers would improve code reuse.
Reply
#6

I don't think it matters. I've done both and tend to have leaner controllers than I used to. Unless your working with a team or on a really large project, the end result will be the same.
Reply
#7

(This post was last modified: 10-28-2015, 05:46 AM by ivantcholakov. Edit Reason: an additional note )

For a request: A thin controller; and a bunch of thin models, probably with hierarchy.
Edit: And if you use HMVC, as a generalized result a request will be served by several thin controllers and several thin models.
Reply
#8

Duplication of code is really bad practice. Even if it's only 5 line of code. In all my projects I use a base controller class and a base model class that every controllers and models extends. Everything needed by more than one controller or one model goes in there.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#9

@includebeer

yup I do the same.
Reply
#10

(10-30-2015, 08:59 PM)includebeer Wrote: Duplication of code is really bad practice. Even if it's only 5 line of code. In all my projects I use a base controller class and a base model class that every controllers and models extends. Everything needed by more than one controller or one model goes in there.

Good approach ...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB