Creating self contained libraries

#1
[eluser]a2s2[/eluser]
I'm trying to create a library that deals with authorization and permission.
I want to put this library into my /system folder so all my applications can benefit from it.
This library should access the database, to save new users or to retrieve then. Since /system folder does not have a /model sub-folder inside I cannot use a model inside my library, i.e., I cannot call $this->load->model('User_Model') inside my library class. Actually, it is not a matter of having /model inside /system, because the Loader class uses APPPATH to load models. So, in order to load a model within a library class I should extend the original Loader class to look into BASEPATH when loading models.

Is there a way to accomplish what I'm trying to do? I do not want to put User_Model inside the /application/models folder since I think the library should be self-contained, i.e., everything should exist into the /system folder so I can use the library with all applications without having to put the model into every /application/models directory.

I know I can access the database directly from within my library class, but since I'm using a framework that offers some goodies why can't I use it (the goodies) within my library?

Thanks in advance for any ideas or suggestions.

#2
[eluser]BrianDHall[/eluser]
First, check out get_instance() - it allows you to get a reference to the invoking CI super-object. So if you use $ci =& get_instance(), you will use $ci->load instead of $this->load - etc.

That gets you part the way there.

As to where you actually can put the files...I do not know about creating such a system that can be installed in one place and shared amongst multiple applications as with the core files.

#3
[eluser]a2s2[/eluser]
Thanks Brian, I know about using $ci object when you are inside a library. I'm actually doing $ci->load instead of $this->load.

So that's what I though, you cannot create a self-contained authentication library using code igniter without hacking it a little. That's why all auth packages I've seen have a lot of files to put under /application folder.

But I still think the ideal solution is to put everything into /system and let the applications use it without further configuration or having to put many files under many directories.

#4
[eluser]BrianDHall[/eluser]
It might be possible somehow, either by extending a core-class or using hooks...but I've never tried or wanted to try, truth be told.

The issue is it is invisible magic, and someone new to your application wouldn't know where the hell the auth system came from. My knowledge of CI tells me everything in the system folder is replacable with new updates of CI, that I can freely delete it or adjust my index.php to look for a different one and nothing should really be much different.

I'd never think to look in system for an auth library unless something told me to, which I think is by design. EllisLabs wants you to leave System to them and put any modified functioning elsewhere, so yes I'd think you'd need to hack it some way.

#5
[eluser]usmc[/eluser]
One Auth Debate

#6
[eluser]jedd[/eluser]
[quote author="a2s2" date="1254451937"]
But I still think the ideal solution is to put everything into /system ...
[/quote]

Brian is right -- think of /system as being out of bounds, and your life will be easier.

I don't see what the problem is with having this as a model that you autoload, especially if you have this down to a single class / file now. Just how many applications are you creating, and how much time do you anticipate saving by not having to copy this file into the /application/models/ directory?

#7
[eluser]a2s2[/eluser]
I thought of /system as a framework "core", something that is used by all applications and that you could extend freely.
I have 4 applications live and 2 to go live until end of year.
Since almost all applications reside on the same server I thought it would be simpler to update a single point, instead of having to update multiple paths every time I roll out a new library version.
I didnt make any time saving estimation, just common sense about updating one directory or multiple.
I just can't understand why you are saying to leave /system alone if this is an open source framework that in its own documentation explains how to extend core classes.
I agree that maybe it will take more work than it will save, so maybe I will let this be.

Thanks for your insights.

#8
[eluser]jedd[/eluser]
I guess it depends when and where you want your pain.

Upgrades to CI are much easier if you haven't mucked around with your system directories/files. Other CI programmers that may work with your software are likely to assume no changes have been made to system files, also. By 'other programmers' I'm including you in 6 months from now, too. OTOH, upgrades to CI aren't usually considered mandatory for extant sites.

Conversely, for your own change management, are you happy to test changes to your library across all 6 of your apps prior to pushing out changes to this one file? If so, I'd suggest symlinks.

A deployment script might give you the same time saving benefits as sticking the file into system/

Quote:I just can’t understand why you are saying to leave /system alone if this is an open source framework that in its own documentation explains how to extend core classes.

You'll doubtless have noted that the documentation explains how to extend core classes by not fiddling with the core files directly.

#9
[eluser]InsiteFX[/eluser]
Take a look at Auth 1.0.6, it uses no hacks all to make it work.

Enjoy
InsiteFX

#10
[eluser]a2s2[/eluser]
[quote author="jedd" date="1254459968"]

Quote:I just can’t understand why you are saying to leave /system alone if this is an open source framework that in its own documentation explains how to extend core classes.

You'll doubtless have noted that the documentation explains how to extend core classes by not fiddling with the core files directly.[/quote]

That's exactly why I've asked for ideas, suggestions.
I will move my files into /application folder and it will work.

Thanks again.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.