Welcome Guest, Not a member yet? Register   Sign In
General MVC (logic) question
#1

[eluser]victorche[/eluser]
I have a simple table in my database, where the site owner is adding all the general site settings (like site title, contacts email, twitter username, etc). I need those settings almost on every page (in the footer mostly, but not only).

So my question is... How should I build my logic about this?

Those are 2 simple functions (save_settings and load_settings), but I should not put them in a helper, as there is a database queries involved. According to the tutorials (and MVC concept in general) every model should contain only functions for one controller (page). So, those functions are not for a model also. A library... Sounds strange to create a library for such a small thing.

I also have a MY_Model file, but I am keeping it for really global CRUD methods. I don't want to put those specific functions in MY_Model also.

Please, tell me which is the correct way to do this Sad
#2

[eluser]WanWizard[/eluser]
If this is database infomation that doesn't change (too) often, but is needed in every reqest, I would definately cache it, and not query the table every time.

And about MY_Model: the idea is that you use this as a base class, not as 'the one and only' model for your application.

So for 'settings' you create a 'Settings' model that extends MY_Model. It will inherit all generic methods defined in your base class. Any specific methods you define in the model itself. No need to put specific methods in you MY_Model class.
#3

[eluser]victorche[/eluser]
@WanWizard, thank you! So, I will keep MY_Model clean... I don't want to say that MY_Model is "the one and only" Smile
I just said that I am keeping it for general CRUD functions. Creating a settings_model is nice, but it means that I have to autoload it? Because I need those functions on almost every page...

About caching... I know it is a better solution, but I am not familiar with all these caching options. Can you give me a hint on how to use the cache?




Theme © iAndrew 2016 - Forum software by © MyBB