Welcome Guest, Not a member yet? Register   Sign In
Autoloading library with custom name?
#1

[eluser]sl3dg3hamm3r[/eluser]
Hey there

If I manually load a library, I could optionally define some other name in the third parameter:
Code:
$this->load->library('session', '', 'myOwnSessionName');

Is this also somehow possible whit the autoload-array?
Code:
$autoload['libraries'] = array('session'); // How could I give my own name?

Thx for any tipp
sl3dg3
#2

[eluser]Andrew Cairns[/eluser]
Interesting question. I don't think this is possible - I am maybe wrong.

Maybe you could use get_instance() inside the library constructor and create a reference manually ?
If this is a CI library, you may have to extend it with MY_Library and dont forget to re-call the parent constructor.

Let us know how this goes, interested to see if you can get anything to work.
#3

[eluser]sl3dg3hamm3r[/eluser]
Yeah that might be an option, but after messing now around for a while in the deep and mighty Loader-class, I conclude it might be not so easy and might turn out into ugly hacks... Sad

My question is based on this thread here, where a session-fix is suggested in order to solve a problem with objects and session. This new session overwrites the old one. Since I autoload the session (I literally use it everywhere), I'd like to keep the name ($this->session->...) under any circumstances.
#4

[eluser]Rahul Anand[/eluser]
Yes you are right there is a option. define your library in autoload.php file. This is the file that autoloads the resources. It will also autoload all of your required library.

Thanks
Rahul
#5

[eluser]Aken[/eluser]
I suggest you figure out what code has been changed around in that thread's solution, and then extend the Sessions class with that code. If you use the MY_Sessions scheme, you won't need to change the sessions name, and the new code will be implemented on top of the default Sessions class.

For a more general solution to being able to use library aliases when auto loading, you'd need to extend the Loading class also, and replace the auto load portion of code with a modified version that accepts aliasing. Sounds like a kinda fun project, actually. Maybe if I find some time I'll try it myself (but don't wait for me, I'll probably forget).
#6

[eluser]Unknown[/eluser]
Had the same issue,

I resolved it with a minor modification.

1) on the autoload I used an associative array
$autoload['libraries'] = array('appcache' => 'CMSAppCache');

where appcache is the alias I want to use for CMSAppCache.php class

2)on Loader.php line 1009 I've modified the libraries loading:

Code:
// Load all other libraries
            foreach ($autoload['libraries'] as $key => $item)
            {
                if ($key){
                    $this->library($item,null,$key);
                }else{
                    $this->library($item);
                }
            }
hope that helps Smile
#7

[eluser]CMCDragonkai[/eluser]
[quote author="shlomi" date="1263160422"]Had the same issue,

I resolved it with a minor modification.

1) on the autoload I used an associative array
$autoload['libraries'] = array('appcache' => 'CMSAppCache');

where appcache is the alias I want to use for CMSAppCache.php class

2)on Loader.php line 1009 I've modified the libraries loading:

Code:
// Load all other libraries
            foreach ($autoload['libraries'] as $key => $item)
            {
                if ($key){
                    $this->library($item,null,$key);
                }else{
                    $this->library($item);
                }
            }
hope that helps Smile[/quote]

That's an amazing fix shlomi!
Does it work if I just extend the loader class rather changing the core?

EDIT:

NVM, I tested it and it works. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB