CodeIgniter and Javascript/Jquery Library

前端 未结 9 837
粉色の甜心
粉色の甜心 2021-02-12 11:51

As title said, I\'m trying to figure out how to use javascript and jquery libraries on CI.

Following instruction in the docs, I load the library in my controller:

9条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-12 12:05

    As we know on the user guide, first, it was an experimental but working. Thr first step is open your config file under application/config/config.php .

    Put the following line :

    // path to JS directory you want to use, I recommended to put the .js file under 'root app/js/yourfile.js'
    
    $config['javascript_location'] = 'js/yourfile.js';
    

    Second step is open your controller, within constructor method, put the following code :

    // Load javascript class
    $this->load->library('javascript');
    $this->load->library('javascript/jquery'); // if u want to use jquery
    

    Then, still in controller file within index method :

    $data['library_src'] = $this->jquery->script(); // Because I refer to use jquery I don't test to use $this->javascript->script().
    

    Then open your view file and put the following code within tag head :

    
    

    That way is working for me, let's try it.

提交回复
热议问题