For every time I make a page in Codeigniter I need to put the links of JS, UI, VALIDITY?

Asked

Viewed 46 times

1

I could use the help of the experts there. Every time some codeigniter application I need to put the links, that usually get in the head or footer inside the page I created?

Example:

I create a User view, and in it I add user and validate the data with https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js. Then to use this validation, it can’t read if I put this link in the head or footer, it only reads if I put it inside the addUsuario view I created.

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

src="jquery-3.3.1.min. js

src="jquery-ui.js script

src="jquery.validate.js script

1 answer

0


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

There are two solutions that work in the same way. In both, you need to have little view pieces 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 then, depending on the choice you make, or whether it matters in the view, this way (ie, 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 else submit the view pieces together in control, this way:

usuario.php (control)

public function minha_funcao() {
    // ...

    $this->load->view('header', $data);                
    $this->load->view('usuario', $data);                
    $this->load->view('footer', $data);                
}
  • Understand! I think using $this->load->view('header', $data) in this way; solve the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.