• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extends CI native library into a package

#1
[eluser]manix[/eluser]
I'm developing a php application using CodeIgniter2, this application resides in:

/public_html/community/
-application
-system
-index.php

This application has its own `My_Session` library (extending from native CI_Session library). Well, everything goes fine here. But, I want to create a Portal/Frontpage at the root directory, for this porpusee I have installed another CI2 application:

/public_html/
-application
-system
-index.php
-community/ (here resides the another CI2 installation)

What I have tried to do is "share" the Session library from `community` to root using the method $this->load->add_package_path() from Loader class, as below:

$this->load->add_package_path('/public_html/community/application/');
$this->load->library('Session');


The problem here is that the Loader class load the Session library from the root system instead package library (community/application/libraries). Did you know how can I deal with it? or if you know a another way to share the Session Library.

Here is where my session library resides:

/public_html/community/application/libraries/My_Session.php

#2
[eluser]manix[/eluser]
Well, I got and this is the final snipped:

1. Add the package
Code:
$this->add_package_path('/public_html/community/application/');

2. Load the Session library from Root CI application
Code:
$this->library('session');

3. Load the library from the application package (cmommunity)
The magic here is that this class extends from Session class previously loaded at point 2.
Code:
$this->library('MY_Session', '', 'csession'); //rename the session to avoid name conflicts


Now, in my root application controllers I can do:
Code:
$this->csession->custom_method();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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