Welcome Guest, Not a member yet? Register   Sign In
cleaning up big jumbled classes
#1

[eluser]geckzilla[/eluser]
Hi, I've been wondering for a long time now how to organize my code better when I end up with a class that's got a lot of functions in it. Say I have an admin class and it needs to be split up into several different sections like users, products, gallery, etc.

I'm relatively new to OOP so I'm making a lot of mistakes or having trouble realizing how to solve common problems but most of them I can find on the forums or php documentation. This time, however, I can't seem to put the right search terms in to find it even though I know someone else must have the same problem. I asked a friend and he mentioned doing the includes which extend the admin class while the class is being instantiated but I have no idea how to do that in the context of codeigniter.

I already thought of making a bunch of separate classes like admin_users, admin_products, etc. but it doesn't sound like the best solution. If anyone has any insight or knows of an old topic that already covers these issues I would greatly appreciate it.
#2

[eluser]The Wizard[/eluser]
hello geckzilla,

you have to study the use of models. please reffer to :
http://ellislab.com/codeigniter/user-gui...odels.html
#3

[eluser]geckzilla[/eluser]
Wow, that seems to give things a whole new level of complexity. My newbie OOP skills can't handle it. I really wish there was a way for me to just split the class up into several separate editable files without it actually being separated from the class. Oh well... I guess my entire basis is wrong.
#4

[eluser]Tom Schlick[/eluser]
well using a model is just like calling in a library or any other function. it just separates your database logic from your other logic so you dont have queries everywhere. its probably one of the best solutions. also you want to mak sure you are following semantic code guidelines like the ones in the user_guide. when you make your code align and look proper its a breeze to read through. and lastly USE COMMENTS IN YOUR CODE!!!
#5

[eluser]The Wizard[/eluser]
controllers and models might look the same but,
controller does the logic, like a teacher saying what you should do and how you should do

a model is like the brain of the teacher, recalling things, or accessing a book/database.

you should think of them in that way, once you figured it out, no one can stop you Smile




Theme © iAndrew 2016 - Forum software by © MyBB