Welcome Guest, Not a member yet? Register   Sign In
Libraries or Models, favouritism?
#21

[eluser]Pygon[/eluser]
[quote author="Hyra" date="1204065239"]
As you can hopefully understand from my point of view (or MVC in general), above example, should just be in a model, and be called by the controller, as it mainly does database actions. The rest (form validation and sending the mail) can be controlled by using the form _library_ and the email _library_

Maybe i was doing things correctly all along and should just stick to using/creating models for the processing of the data, using the prebuilt libraries of CI "as is". Think i just got confused by finding all sorts of "Auth Libraries for CodeIgniter" which confuzzled me as to what the difference between a model and a library actually is Smile[/quote]

Going back to my PDF example, in your situation you would have:

pdf_type1_model, pdf_type2_model, pdf_type3_model;

Each of your models would have a seperate function for creating a pdf. What happens if you need to change the way a PDF is created -- maybe there was something wrong with the way your create function was working. Instead of being able to update your function in one place, the library, you have to modify all three models.

The premiss of this is very similar to Object Oriented Programming and class inheritance. An initial class (library) provides the basic functionality, where as other classes that inherit from this provide program specific functionality (models).
#22

[eluser]xwero[/eluser]
[quote author="Pygon" date="1204074069"]Each of your models would have a seperate function for creating a pdf. What happens if you need to change the way a PDF is created -- maybe there was something wrong with the way your create function was working. Instead of being able to update your function in one place, the library, you have to modify all three models.[/quote]
You create the pdf in your model? Isn't that a violation of the MVC rules?

I don't care to much about rules. For me it is about writing as little code as possible to come to the results that are wanted. If i can write a function that can replace several functions i rather do that than be conform with the rules. Patterns aren't the alpha and omega of programming.
#23

[eluser]captainbeef[/eluser]
Hello,
I see that this thread has evolved to include some specific examples.

I would like to pose a general question, in the form of several questions.

Accepting that the MVC framework is to be followed in an architectural sense, does the CI base Model object actually contain any specific functions that differentiate it for data handling?

What are the key functional differences between the Model and the Library objects?

Say we have 2 tasks to extend from the main controller, one involving db data access/update and one not. If we step outside the MVC architecture for a moment, and just look at the CI Model and Library objects based purely on their functional offerings, is there anything compelling the choice of one or the other for the afor-mentioned tasks?
#24

[eluser]wiredesignz[/eluser]
Models have automatic access to the CI core library objects, ie: database, router etc, almost any object available to the Controller is available to a Model.

Libraries do not, You need to provide these features.
#25

[eluser]captainbeef[/eluser]
Ah I see.
Thanks Smile




Theme © iAndrew 2016 - Forum software by © MyBB