Codeigniter - how to include a dynamic javascript file in a view

前端 未结 1 1990
再見小時候
再見小時候 2021-01-15 22:31

I\'m trying to include the following code block (which contains some dynamic values) in my header view if certain conditions are met.



        
相关标签:
1条回答
  • 2021-01-15 22:59

    Load the JS view in the controller and pass it over to the controller.

    $jsview = $this->load->view('view_name', array(), true);

    Note that the third parameter is set to true. That will return the view to you instead of outputting the view to the screen.

    Then, pass it over to your main view.

    $data['js'] = $jsview;
    
    $this->load->view('mainview',$data);
    

    That is a better MVC approach as the logic remains in the controller.

    0 讨论(0)
提交回复
热议问题