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.
– Diego Ramos