Codeigniter: How to include javascript files

前端 未结 6 619
一向
一向 2020-12-08 21:10

Hello I just started working with CodeIgniter framework. My current directory structure is

Demo(Project name)
 +System
 +Application
   -Controllers
      de         


        
6条回答
  •  长情又很酷
    2020-12-08 21:53

    The $data variable sometimes may be lost if you have nested views and you don't pass it as an argument to the children/nested views.

    I found a simple solution that is working very smoothly to me:

    In your current view file you setup your script like this:

    $this->scripts[] = '/js/myscript.js';

    at your footer or {whatever.php} file you insert this code:

        scripts))
            foreach($this->scripts as $script) :
         ?>
                
        
    

    If you need only a pice of javascript code, you can always use anonymous functions like this:

    RenderScript[] = function() {
    ?>
          
    
    

    and at the bottom:

    RenderScript))
                foreach($this->RenderScript as $script) {
                    $script();
                }
        ?>
    

提交回复
热议问题