CodeIgniter and Javascript/Jquery Library

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

    Because this driver is experimental the documentation isn't quite there yet. But I was able to find a solution.

    First, the documentation has an error in it. Unless you change the core Javascript library (not suggested) the reference variable is not $script_head but in fact$script_foot.

    Second, once you've finished making your calls, it seems you need to run

    $this->javascript->external();
    

    and

    $this->javascript->compile();
    

    These functions set the $library_src and $script_foot variables.

    To put it all together, in your controller you would have:

    class Some_Controller extends CI_Controller {
       public function index()
       {
           $this->javascript->click('#button', "alert('Hello!');");
           $this->javascript->external();
           $this->javascript->compile();
           $this->load->view('index');
       }
    }
    

    In your view you would have

    
      
         
         
    

提交回复
热议问题