pushing files to a view page through controller

Viewed 74

in Laravel we can stack scripts separately by the name in view page like below

      @push('scripts')
          <script src="/example.js"></script>
      @endpush

      @stack('scripts')

i need a replacement of this in CodeIgniter. any help is acceptable

1 Answers

i dont know how to do that in codeigniter, but i have my own way

1. Master view file

<html lang="en">
<head>
    Your Header
</head>
<body>
<div class="wrapper">
    <!-- Navbar -->
    Your Navbar
    <!-- /Navbar -->
    <!-- Sidebar -->
    Your Sidebar
    <!-- /Sidebar -->
    <div class="main-panel">
        <div class="content">
            <div class="page-inner">
                <?php isset($content) ? getContentB($content) : null ?>
            </div>
        </div>
        <footer class="footer">
            <div class="container-fluid">
                <div class="copyright ml-auto">
                    2020
                </div>
            </div>
        </footer>
    </div>
</div>
    Your footer/load js file
    <?php isset($scriptfooter) ? getScriptFooterB($scriptfooter) : null ?>
</body>

2. Helper

this helper is used to retrieve the view from the controller

function getContentB($filename){
   $CI = & get_instance();
   return $CI->load->view($filename);
}

function getScriptFooterB($file){
   $CI = & get_instance();
   return $CI->load->view($file);
}

3. Controller

public function index(){
    $data['content'] = //Your content file location;
    $data['scriptfooter'] = //Your script/javascript location;

    $this->load->view('master', $data);
}
Related