Welcome Guest, Not a member yet? Register   Sign In
How to use abstract classes as libraries ?
#1

[eluser]satisfactioN[/eluser]
Hello,

I am new to CodeIgniter.

I have a problem here, suppose I am trying to create an object-oriented design for a sale system with the following classes:

AbstractItem
Product (Inherits from AbstractItem)
DVD (Inherits from products)
etc..

I've tried to create a library abstract class (for example AbstractItem.php) but I cannot because of the Loader.php. I get the following error:

"Fatal error: Cannot instantiate abstract class 'AbstractItem' in C:\wamp\<censored>\system\librairies\Loader.php"

Since the Loader.php instatiates every classes we want to load create, my question is:
Is there a way to use abstract classes, or how would you implement such an oriented-object design that requires the use of abstract classes into CodeIgniter ?

Thank you very much.
____
doM
#2

[eluser]satisfactioN[/eluser]
Anyone please ?

It has to be possible ?

I am trying to define objects that I will in my models and maybe in my views.

Maybe I shouldn't create those classes in the library folder, what else then ?

thank you !
#3

[eluser]esra[/eluser]
You are probably going to have to subclass (extend) Loader.php. resulting in a framework that only supports PHP 5. For some ideas, you might look at the Kohana fork which is PHP5 strict. I'm not too fond of forks, but in this particular case, you might not have a choice.
#4

[eluser]satisfactioN[/eluser]
Oh I found it, it'll work with pluggins.

Pluggins were actually what I was looking for. Wink

thanks esra.
#5

[eluser]Unknown[/eluser]
The dirty way to do this is to define the abstract class at the top of the library file, then extend the library class below it.

&lt;?php
abstract class myAbstract
{
.. stuff here
}

class libClass extends myAbstract
{
.. stuff here
}
?&gt;

Then you ..->load->library('libClass') as usual;

This is by no means a great way of doing it, but for limited use it works fine (minus violating a dozen or so OOP rules)




Theme © iAndrew 2016 - Forum software by © MyBB