Welcome Guest, Not a member yet? Register   Sign In
Extending Base Libraries via. "Packages"
#1

[eluser]Unknown[/eluser]
Version: CI 2.0 (Default Install)

Hi, I am experiencing unexpected results. It seems that you cannot extend base libraries through packages. In my particular instance I was trying to extend form_validation class.
Since this is not a core class It must be stored in the ./application/libraries. My attempt at storing it in ./package_path/libraries was unsuccessful. Here is my final solution to the issue, however I feel it is more off a hack than a solution.

Code:
//I included the class myself
require_once(BASEPATH."libraries/Form_validation.php");

class MY_Form_validation extends CI_Form_validation {
    /**
    * Constructor
    */
    function __construct($rules)
    {
        parent::__construct($rules);
    }
}

/* End of file MY_form_validation.php */
/* Location: ./packages/libraries/MY_form_validation.php */

And here is my controller

Code:
class PAGE_EXAMPLE extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->library('MY_form_validation','','form_validation');
        //Rest of method...
    }
}

/* End of file PAGE_EXAMPLE.php */
/* Location: ./application/controllers/PAGE_EXAMPLE.php */

Let me know what you guys think

Thanks,
Kwaight
#2

[eluser]WanWizard[/eluser]
You can extend a library though a package, only the 'autoloading' of the extended class doesn't happen as you have discovered.

A cleaner solution might be to extend the loader library so that it looks in packages as well?




Theme © iAndrew 2016 - Forum software by © MyBB