codeigniter库继承以及使用


codeigniter库类继承与使用
查找相关文章:codeigniter

在codeigniter帮助文档中写道

https://ellislab.com/codeigniter/user-guide/general/creating_libraries.html


注意文件名大小写

Your new class name and filename must be prefixed with MY_ (this item is configurable. See below.).

For example, to extend the native Email class you'll create a file named application/libraries/MY_Email.php, and declare your class with:

class MY_Email extends CI_Email {

}

Note: If you need to use a constructor in your class make sure you extend the parent constructor:

class MY_Email extends CI_Email {

    public function __construct()
    {
        parent::__construct();
    }
    
    public function my_func(){
        echo 123;
    }
}

使用子类,只需要加载父类就可以了,好变态的逻辑

Loading Your Sub-class

To load your sub-class you'll use the standard syntax normally used. DO NOT include your prefix. For example, to load the example above, which extends the Email class, you will use:

$this->load->library('email');
$this->email->my_func();
//将打印出123