CI3

CI3 라이브러리

수수깡깡 2022. 9. 23. 15:22
728x90
반응형

CI3 라이브러리 사용

 

#내장된 라이브러리 사용

ex) 세션라이브러리  
$this->load->library('session');
ex) 페이징 라이브러리
$this->load->library('pagination');

 

#사용자 라이브러리 사용 

$this->load->library('라이브러리명');
$this->라이브러리명 = new 라이브러리명();


#라이브러리 내 함수 사용 

$this->라이브러리명->라이브러리함수명();

 

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test extends CI_Controller {

    public function __construct() 
    {
    	// 내장 라이브러리 사용
        parent::__construct();
        $this->load->library('session'); // 세션 라이브러리 
        $this->load->library('pagination');// 페이지 라이브러리 
        $this->load->helper('url'); // url 라이브러리 
    }
    
    public function test()
    {
    	// 사용자 라이브러리 사용
        $this->load->library('Test_library');
        $this->Test_library = new Test_library();

        // 라이브러리 내 함수 사용 
        $this->Test_library->TestLibFun();
    }
}

 

# 사용자 라이브러리 생성

/libraries/Test_library.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test_library {

        TestLibFun()
        {
            //
        }

}
728x90
반응형