Codeigniter best practice - multiple models

Just a quick question about best practice MVC development.

Let's say that I have two controllers (cont1, cont2), each of which uses a separate model, model1 and model2.

all files are complex, models contain dozens of methods.

Let's say I finished developing the first controller, and I'm in the middle of working on the second. I need to create a method in model 2 that will be exactly the same as one of the methods in model1. This is just a tiny method, for example, to get a list of categories.

What is the best approach to work - should I duplicate the method and include it in my model2, or should I get it from model1?

It would be wise to get it from model1, but I don’t know if this will affect the runtime, since it will have to load both models.

I would appreciate some feedback.

thanks to

+3
source share
3 answers

Downloading the second model will not have a noticeable effect on runtime. This is probably the way to go.

In addition, each model must encapsulate the data logic for a particular “object”. You can think of each model almost like a database table. That way, you probably really don't want to have the same method in two different places - and if you do, you might want to create a plugin.

+3
source

, . , / , , . , "" 1 1 .

+1

. , , codeigniter . , , . , . ( ).

0

Source: https://habr.com/ru/post/1735489/


All Articles