CodeIgniter and Javascript/Jquery Library

前端 未结 9 856
粉色の甜心
粉色の甜心 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:25

    Put the code in the config.php like this:

    $config['javascript_location'] = 'js/jquery/jquery.js';
    $config['javascript_ajax_img'] = 'images/ajax-loader.gif';
    

    In your controller file (e.g. controllers/sample.php) type this codes:

     function __construct()
       {
            parent::__construct();
                $this->load->library('javascript');                    
       }
    
    function index()
    {
    
        $data['library_src'] = $this->jquery->script();
        $data['script_head'] = $this->jquery->_compile();
    
        $this->load->view('sampleview', $data);
    
    }
    

    In your view file (e.g. views/sampleview.php) type this codes:

    
    
    

    This works for me. I hope it works for you too. XD

提交回复
热议问题