Welcome Guest, Not a member yet? Register   Sign In
Library Vs Model
#11

[eluser]Peng Kong[/eluser]
here's the way i see it.

models do all the database talking (data in and out)... no one else does it.

view contain all the presentation (html, css, js)... no where else contains it.

i think this way of looking at models are views are pretty similar from developer to developer.

controllers functions 'map' to one or more views.
They determines which view to show based on "your logic" which determines on the flow.

"your logic" that is specific to that controller's function stays in the controller.
"your logic" that is 'across the board' (aka reusable) goes into libraries, helpers and plugins.

Libraries, as mentioned, contains "your logic" which is reusable to many parts of your application. Libraries can make use of helpers and plugins.

Helpers are just simple, useful, reusable, standalone functions.

Plugins are many related functions and help achieve a common purpose. They are strictly standalone (no dependency). Plugins have a clearly defined interface for you to call anywhere in "your logic".

---

However, i'm finding that even after doing all that, you will get to a stage where complex applications have too many views, models and controllers.

Things start to get messy and you ask yourself, "How do i group up related views, models and controllers into folders... rather then just ONE folder for ALL the views, ONE folder for ALL the models and ONE folder for ALL the controllers".

There's where Modular Extensions by Wiredesignz comes into play.

After using Modular Extensions, i prefer to put more module logic into controllers and application logic into libraries (for other modules to use).

maybe i don't know better but i feel this is a flexible D.R.Y. approach.
#12

[eluser]Unknown[/eluser]
[quote author="Peng Kong" date="1265458757"]here's the way i see it.

models do all the database talking (data in and out)... no one else does it.

...

Libraries, as mentioned, contains "your logic" which is reusable to many parts of your application. Libraries can make use of helpers and plugins.

[/quote]

I'm new user for CodeIgniter and have same problems of this topic's.

Now write the Ecommerce Engine with follow parts:
Users,
Catalog,
Basket.

User => I use Model that content Logic and Database Access.
Basket => I use Model for same reasons
Catalog => I write all logic structure and access ONLY api from other CI application (no query into Database). Now, is Model or library?

The question for me is this: Models is for access Data (Database, Api, WebServices, etc...) or ONLY Database (Database is only ONE source of data)?

Ohterwise: If i write one CI application that write and read information only with webservices.... this Application Not have Models and all logic is into library?

NOTE: This Catalog is NOT generic code (reusable for other application Not Ecommerce).

Thank's for response ad excuse me for my english.
#13

[eluser]mx_code_monkey[/eluser]
[quote author="theprodigy" date="1265077729"]
Depending on how complex the app gets, I sometimes have the controller communicate strictly with the libraries, and the libraries communicate with the models. I'll use the controller to set/get the attributes of the library object, then call a save function. The save function in the library calls the insert method of the model. In complex apps, it seems to be easier that way. In smaller, scaled down apps, it's easier to leave the libraries out of the picture.
.[/quote]

I am developing a very large app prototype and the reason it seems to me that creating new libraries is clearly a better OO approach over the CI & get_instance way of loading models within models, is frankly, a function named 'get_instance' from their framework doesn't sound very scalable, from the stack overflow prevention perspective.. it probably works fine for maybe even 100s's of smiulataneous users, but try 10,000.. and depending on their size and strength of your cache, its probably a recipie for disaster if your app gets super popular and it must deliver.

It became clear in design mode early on that with any MVC, creating class interfaces for models to communication with other models is simply too much of a headache, but so is loading models within models for me. I didn't know what makes the better practice with this framework though: custom libraries or custom hooks.? but this quote above is what I was looking for from an code-ignit0r experienced in more complex apps, and I thus will try using libraries in this fashion to communicate with models via controllers. I can see that the new driver component will be good for doing the same thing with multiple sets of methods for communicating with those models, such as a permission driver to manage roles and access to certain models..

i can see others don't see your logic in this approach, but your strategy will give me a good lead for design patterns involving application data (such as navigation, settings, client data, user preferences) vs. real object data that is user created and shared within the application.

Thank you for your two cents!! Smile **


#14

[eluser]mx_code_monkey[/eluser]
[quote author="Peng Kong" date="1265440757"]

Things start to get messy and you ask yourself, "How do i group up related views, models and controllers into folders... rather then just ONE folder for ALL the views, ONE folder for ALL the models and ONE folder for ALL the controllers".

There's where Modular Extensions by Wiredesignz comes into play.

After using Modular Extensions, i prefer to put more module logic into controllers and application logic into libraries (for other modules to use).

maybe i don't know better but i feel this is a flexible D.R.Y. approach.[/quote]

I will look into this too, more than I already have. the obvious advantage of being able to load other controllers from controllers is what seems interesting, more so than having to deal with heavily populated folders...Loading other controllers from a controller has that flag in my head that says it sounds an awful lot like something against best practice, something I would definitely have the impulse to do.. given that we were talking about loading models within models.. I know this has been solved with adding a new layer, making it 'modular' as they say - but still kind of hesitant even for a large application - module 'packages' still seem like something a library is for..




Theme © iAndrew 2016 - Forum software by © MyBB