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

[eluser]elci[/eluser]
Is there any "best practice" when it comes to extending custom libraries?

I started reworking an old web application project with CI, but I got to a stage where I had to figure out how to include my old custom classes into the framework's paradigms.
I'll use a very cliche simplified example of what I need done:

class vehicle{}

class sedan extends vehicle{}
class mercedes extends sedan{}

class truck extends vehicle{}
class ford extends truck{}

and so on ...

load->library() is strictly tied to the classes' names, and somehow it doesn't feel right to add to add my own core classes, and that wouldn't solve the problem of chaining more than two classes. So far I have not been able to go around the use of straight PHP include() for the base classes.

Is there a CI way of doing this?
#2

[eluser]WanWizard[/eluser]
No, CI doesn't support non-singleton objects.

You can work around it by loading them using $this->load->model(), deleting the $CI->modelname property created (if required), and then use new to create new objects. Or use include(). Or create an autoload method.
#3

[eluser]elci[/eluser]
Thanks for the fast reply,

for the time being I think I'll stick with include(), it seems easier for someone else who may be working on the project to grasp the idea.




Theme © iAndrew 2016 - Forum software by © MyBB