Welcome Guest, Not a member yet? Register   Sign In
Extending classes
#1

[eluser]stuffradio[/eluser]
I stupidly hadn't really looked at extending classes until today, but now I realize what I could do. I can use something like My_Controller to use with a permission system, and I'm sure lots more things.

What are the most common classes you guys extend and what do you do to make your code the most efficient and most reusable so you don't have to write things over again?
#2

[eluser]kilishan[/eluser]
Yea, MY_Controller is a perfect example. I'll typically have a Front_Controller and an Admin_Controller class in the MY_Controller file. The Admin_Controller will be responsible for loading any models that are needed everywhere in the admin section of the site. It also takes care of checking the user has permissions to be there. That way I don't have to worry about it elsewhere.

Keeping with the controller portion, I autoload as little as possible (typically only my session, database and templating classes). Then I'll load those models/libraries that are needed throughout the frontend or backend in their respective Controller classes.

MY_Model is also a good one to look into, unless you're using something like DataMapper or IgnitedRecord. You can setup a base model that has all of your standard CRUD features and maybe a couple of utility functions, then base all other models off of that. Though I've had one situation where I needed an NSTree for a couple of the models, and put another base class in the MY_model file so that I had that core code in one place.
#3

[eluser]Unknown[/eluser]
t
#4

[eluser]stuffradio[/eluser]
So if I understand this correctly, here is what I was thinking.

I will have two base controllers, MX_Admin and MX_Public. (I'm using HMVC) They both have the security class loaded in them. I then load any of the most common things I would need access to in both of them.

In Public I have the most common things for front end stuff, and Admin I would do the same for Backend operations. Is this what everyone does?




Theme © iAndrew 2016 - Forum software by © MyBB