Welcome Guest, Not a member yet? Register   Sign In
Grouping up functions for controllers and models.

(10-24-2019, 04:10 AM)PaulD Wrote:
(10-23-2019, 11:37 PM)dweenator Wrote: This is because i have other projects that i completely abandoned because i couldn't get into them after i stopped for awhile and have a look at my project that is messy(in my opinion) that i would rather restart the whole thing from the groundup than to continue them.

Smile We have all been there!

I have one hobby project that I have written and rewritten about five times now. Still cannot get it right.

The division of what goes in a model or a library, or what purpose your model or library is actually for, is quite an art form. Very much like database design. Get your tables wrong at the outset and your queries can become a nightmare. Get your libraries or models wrong, and your code becomes a mess.

In your example everything is part of a story, so your 'Story' library could contain everything. I would have a story library for creating new stories, getting stories, listing stories, etc. Anything at a 'Story' level. Then a chapters library for getting chapters for a story, adding chapters, reading chapters, editing chapters etc. Anything at a chapter level.

You could have a reading_library, an editing_library and a creation_library too. Then have a chapters model and a stories model that these libraries use.

There are lots of ways to do anything, it all depends on your plans and ambitions.

Good luck with it though, there is no 'right' answer.


Your answer has enlightened me.

I already knew from the start that there were no 'correct' answer to my question, i think i've asked this question once on stack and i got downvoted so hard there.

Anyway, i personally haven't tried making my own custom library so i will just divide my controller onto what i have originally in mind( story controller for anything story and chapter for anything chapter).

Once i'm done with this i'll explore onto the other ways you have suggested starting especially with making my own custom libraries. 

I think that's an integral part to codeigniter. Being able to make your own library and/or helper.

For example, i could simply make my own account library for everything related to it(creation,validation, etc.) and reuse it on all my projects. Possibilities are endless.


Messages In This Thread
RE: Grouping up functions for controllers and models. - by dweenator - 10-24-2019, 04:46 AM

Theme © iAndrew 2016 - Forum software by © MyBB