Welcome Guest, Not a member yet? Register   Sign In
Can I extend a CI Library in a Package?
#1

[eluser]Drew J[/eluser]
My testing is telling me no; I'm wondering if anyone knows for sure.

I have some libraries I created in my shared Package (shared models, libraries, etc) and they load just fine. If I try a file like "MY_Encrypt.php" to extend the CI Encrypt Library; I don't appear to have access to the new functions in the loaded (and extended) library.

If I move that file (MY_Encrypt.php) to my /application/libraries folder, it works just fine.

Is this a bug, a known limitation or an unknown limitation?
#2

[eluser]wiredesignz[/eluser]
Of course if you include the base class manually you can extend anything. You are not forced to use the MY_ subclass prefix when extending CI classes.
Code:
<?php

require BASEPATH.'libraries/Encrypt.php';

class Encrypt extends CI_Encrypt {}
#3

[eluser]Drew J[/eluser]
Ok, I found that changing the file and class name to "Encrypt" instead of "MY_Encrypt" in my package causes it to be used. (Which makes me think it needs to be changed so that a "MY_X.php" file works from a package)

However, using your suggestion, I still get a method not found error when calling "$this->encrypt->new_function()" - (Call to undefined method CI_Encrypt::new_function())

Here's my extended file (Encrypt.php in my shared package). I can confirm this file is being called (inserting an "echo" in this file before the class declaration works).
Code:
require BASEPATH.'libraries/Encrypt.php';

class Encrypt extends CI_Encrypt {
    
    public function __construct()
    {
        parent::__construct();
    }
    
    public function new_function($string = NULL)
    {
        echo 'test';
    }
    
}

I'm pretty stumped... but it's also late. Maybe I just need to sleep on it?




Theme © iAndrew 2016 - Forum software by © MyBB