CodeIgniter Forums

Full Version: Anatomy of a library - how should they interact with the database?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]warpkid[/eluser]
Hi There,

I am building a little site and re-factoring some code that a colleague wrote to manage the editing of pages - a content management system of sorts.
This kinda code strikes me as something that would be suited to a library, as its something we could use across a multitude of sites.

My question is, is there a specific best practise way of putting a library like this together?
The code makes use of a model to access the database - is it the done thing to build a library that relies on a associated model?
Also, is it best to not access post data from within a library and instead have all required data passed in? Just to make the library more 'generic'.

I know I could probably do it anyway I liked, but Id like to get an idea of what best practise dictates in terms of library creation.

Thanks!

El Forum

[eluser]Thorpe Obazee[/eluser]
This might be something you want to read:

MVC Discussion

El Forum

[eluser]n0xie[/eluser]
[quote author="warpkid" date="1270044220"]
My question is, is there a specific best practise way of putting a library like this together?
The code makes use of a model to access the database - is it the done thing to build a library that relies on a associated model?[/quote]
I think what you are looking for is modules. In this case you would create a 'page' module which has some basic CMS like behaviour which you drop into an application and which handles the CRUD of basic pages. The module would consist of some model(s) to do basic CRUD, some controller(s) and some scaffolding view(s). PyroCMS works on this principle but it is not hard to build a system like this yourself. There is very good HMVC implementation made by wiredesignz you could checkout.

El Forum

[eluser]warpkid[/eluser]
Thanks for the replies guys. I shall check out the links you supplied and see what I can come up with.

El Forum

[eluser]warpkid[/eluser]
[quote author="PDP" date="1270044428"]This might be something you want to read:

MVC Discussion[/quote]

Great link, thanks. Its cleared things up