• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
load class and not instantiate

#1
[eluser]uniq[/eluser]
Hello,

How to load class in CI 2 and not instantiate it?

P.S. in CI 1.7+ it was simple by passing second param to load_class function

#2
[eluser]toopay[/eluser]
As long as i aware of CI upgrade from 1.7.x to 2.x, there is nothing change at how loader class works, related with your issue above.

#3
[eluser]uniq[/eluser]
FYI

CI 1.7.x system/codeigniter/common.php
Code:
* @access    public
* @param    string    the class name being requested
* @param    bool    optional flag that lets classes get loaded but not instantiated
* @return    object
*/
function &load;_class($class, $instantiate = TRUE)
{
...

CI 2.x system/core/common.php
Code:
* @access    public
* @param    string    the class name being requested
* @param    string    the directory where the class should be found
* @param    string    the class name prefix
* @return    object
*/
function &load;_class($class, $directory = 'libraries', $prefix = 'CI_')
{
...

and the problem is that I have lib with private __construct:
Code:
private function __construct()
{
  //disabled for Singleton pattern
}

of course I can use requered_once but then I have to work with include paths ...

#4
[eluser]toopay[/eluser]
Thanks for remind me that i missread your thread (what i've looked up is loader class, file under system/core/Loader.php).

Back to your issues, what about extending Common.php?

PS : you can wrap your code, on code tags
Code:
// Remove any spaces
[ code]
// your code here
[ /code]

#5
[eluser]uniq[/eluser]
thanks for [ code] Smile

I would extend it if there is no way to do it with default CI

#6
[eluser]ColonelChlorine[/eluser]
Bit of an old thread, but thought I'd throw my 2c in because I ran into the same issue creating my own library which I didn't want CI to interfere with.

I didn't try extending the Common.php file (I don't even think you can because it's just a collection of functions) ... however I wrote my own loader. Threw it in as a helper. It basically accepts a class name, looks for it in the APPPATH."classes" folder and does a require_once().

That's not far off how CI does it's loader, except it does all the singleton + instantiation crap as well.

Works like a charm for me.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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