Welcome Guest, Not a member yet? Register   Sign In
Extending Native Libraries or Replacing Native Libraries with Your Versions
#1

Hi all,
I want to extend the Log library to customize the log format. I have create my own class MY_Log extending CI_Log in application/libraries. When I load this library I have this error: Unable to load the requested class: Log.
I have copied the original Log class system/core/Log to application/libraries to replace the native one, but I have the same error.
I am using codeigniter 3.0.6
Can somebody help me to solve this issue ?
Reply
#2

In the future fyi:

If the Library you are extending is in the:

system/core then it goes in application/core

system/libraries it goes in application/libraries
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 09-12-2016, 11:49 AM by dave friend.)

You do not need to copy the original file when extending a Core class. In fact, you should not do that.

To extend the log library it would look something like this

Code:
class My_Log extends CI_Log {

  protected $my_custom_var;

   public function __construct()
   {
     parent :: __construct();
     //your stuff here
     $this->my_custom_var = "Custom Loggers Are Great!";
   }

   //your new class function
    public function my_special_logger()
   {
       //your code
   }

    //overwrite a base class function
    public function write_log($level, $msg)
    {
       //your file writing routines here (which might include copying code from Log.php in this case)
    }

}
Reply
#4

(09-12-2016, 09:31 AM)InsiteFX Wrote: In the future fyi:

If the Library you are extending is in the:

system/core then it goes in application/core

system/libraries it goes in application/libraries

I have noticed it. Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB