Welcome Guest, Not a member yet? Register   Sign In
best practice separating business logic from controller and model
#1

Hi Eeveryone,
is there any best practice in CI4 to manage a separate layer for business logic which has model references and can be used in controllers so that redundancy can be minimized and have a better code organization?

thanks
Reply
#2

its been 6 hours no answer so let me kick it off : i have a feelig that Lonnie new book might answer this:

https://leanpub.com/codeigniter4foundations

also depends on complexity. The most basic pattern is :

view : presentation and what web surfer sees. Can be made more compact. Instead of a "header" view , "content" view and "footer" view, that make up web page just use "layout".
model: connects to and models data
controller : basic logic

so for instance i use PHPMailer in a controller the lines are not excessive so i could user a "manager class" which controller will use but from a birds eye view , it probably won't reduce code.Then Lonnie talks about dependency injection, entities and so on. I think what you find works best for you is the way; tidying up code and reducing stuff will flow naturally , at least it does in my case .
Reply
#3

(12-06-2020, 11:40 AM)captain-sensible Wrote: its been 6 hours no answer so let me kick it off : i have a feelig that Lonnie new book might answer this:

https://leanpub.com/codeigniter4foundations

also depends on complexity. The most basic pattern is :

view : presentation and what web surfer sees. Can be made more compact. Instead of a "header" view , "content" view and "footer" view, that make up web page just use "layout". 
model: connects to and models data
controller : basic logic

so for instance i use PHPMailer in a controller the lines are not excessive so i could user a "manager class" which controller will use but from a birds eye view , it probably won't reduce code.Then Lonnie talks about dependency injection, entities and so on. I think what you find works best for you is the way; tidying up code and reducing stuff will flow naturally , at least it does in my case .

Business logic should be in model, separated from DB model. Business logic should be omitted from view and controller. For CI4 structure probably the best place for business logic is Domain folder under app folder.
I'm not expert at that field but worked in a company that was trying to develop using Domain Driven Design (DDD) approach.
--------
blagi

https://blog.blagi.net/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB