Welcome Guest, Not a member yet? Register   Sign In
[Q] where can I declare a class to share between library, controllers
#1

[eluser]vlad_ci[/eluser]
Hi, I would like to define a class
(that inherits from the SplArray) and pass it arround
(as reference) between
various Library classes and the controller.

Where can I create the definition of this class, such
that all the diferrent components are aware of the definition
(and it will be instanciated in one of my Library classes)?

Please, note I thought of declaring this class as a separate library,
however the problem there is that when loaded, it will be 'attached'
to the Controller (because Controller is the only thing that do
load->library) -- and I do not want that.


Thank you
#2

[eluser]vlad_ci[/eluser]
Well, probably my question was too basic so did not get any replies.

This is what I did and it seems to suite my primitive needs sofar.

Basically in my controller before declaring my controller class,
I did this

Code:
function __autoload ($cname)
{
    require_once(APPPATH.'libraries/CCommonData.php');
}

I saw many examples people attempting to have a 'generic'
autoloader that would search for certain paths/etc depending
on the class name $cname to autoload.

But all I wanted to do is to emulate C++ include files --
where I can have many classes declared within one include
(and this seems to let me do that). I put those things in the library
directory even though I do not plan to use CI->load->library
(for the reason explained in my original post).


This __autoload construct apparently also improves performance
as when I have more and more files being used during the Controller
processing -- it will automagically execute my require_once only
if a given has not been declared yet.

Wanted to hear if people have any comments on the above.
(this is PHP5 only, I believe)

Thanks in advance




Theme © iAndrew 2016 - Forum software by © MyBB