Every time I make a page in Codeigniter I need to put the JS, UI, VALID links?

1

I need the help of the experts there. Every time I have some codeigniter application I need to put the links, which usually stay in the head or footer within the page I created?

Example:

I create a User view, and in it I add user and validate the data with link . Al to use this validation, it can not read if I put this link in the head or in the footer, just read if I put it inside the view addUsuario that I created.

I want to put in the header or in the footer and everything I do inside a view it will read the:

  

script src="jquery-3.3.1.min.js

     

script src="jquery-ui.js

     

script src="jquery.validate.js

    
asked by anonymous 06.07.2018 / 23:04

1 answer

0

Hello, no, you do not need to, nor should you be repeating the same information in all views (such as importing scripts). In your view user you should only worry about what is related to it, that is, with the "core."

There are two solutions that work identically. In both, you need to have bits of view to represent HTML elements like header and footer, for example:

header.php (view)

<!doctype html>
<html lang="pt">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title><?=$page_title?></title>
        <link rel="shortcut icon" href="<?=site_url('favicon2.ico')?>" type="image/x-icon">
        <link rel="icon" href="<?=site_url('favicon2.ico')?>" type="image/x-icon">        
        <link rel="stylesheet" href="<?=site_url('/css/bootstrap.min.css')?>">
    </head>
    <body>

footer.php (view)

        <footer class="footer">        
            <script src="<?=site_url('js/jquery.min.js')?>"></script>
            <script src="<?=site_url('js/bootstrap.min.js')?>"></script>      
            <script>
            <!-- Por exemplo um script só para uma view em específico -->
            <?=$page_script?>
            </script>
        </footer>
    </body>
</html>

And so, depending on the choice you make, or if you import it into the view, this way (that is, every view will have a require at the beginning and another at the end):

usuario.php (view)

<?php require_once(dirname(__FILE__).'/header.php'); ?>
meu conteúdo da view usuário...
<?php require_once(dirname(__FILE__).'/footer.php'); ?>

Or, you can submit the pieces of view together in the control, like this:

usuario.php (control)

public function minha_funcao() {
    // ...

    $this->load->view('header', $data);                
    $this->load->view('usuario', $data);                
    $this->load->view('footer', $data);                
}
    
23.07.2018 / 19:40