Reputation: 684
I want to include/use bootstrap in all my controllers/views without having to load each css/js in each view file, so I have done this:
Installed Composer Bootstrap
composer require twbs/bootstrap
My Index Controller:
public function index() {
// Composer Autoloader
require VENDORPATH.'autoload.php';
require_once BASEPATH.'core/CodeIgniter.php';
echo '<div class="section jumbotron text-center">Yu in index son.</div>';
}
VENDORPATH = myhomefolder../vendor/
vendor/autoload.php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit9d54f40b1177ed0ebd8d1d378ec06d06::getLoader();
/composer.json
{
"require": {
"twbs/bootstrap": "^3.3"
}
}
I don't know what to do now, I have searched all the web but it only says things about other packages or something not related and Im stuck in this right now, if someone in advance can help, I would appreciate, thank you.
Upvotes: 1
Views: 3931
Reputation: 325
What I do, is that I use a "main" template, which includes the css, js, head, body, etc... Then, inside my body tag, I do the $this->load->view('folder/function', $data); which processes the internal view... Do I make sense ???
Main View:
<html>
<head>
<?php $this->load->view('html/head', $view_data); ?>
</head>
<body lang="es">
<div class="container">
<?php $this->load->view('html/header')?>
<div class="contenido">
<?php if (isset($which_view)) $this->load->view($which_view, $view_data)?>
</div>
<?php $this->load->view('html/footer');?>
</div>
</body>
</html>
And finally, I create a small "inner-view" in a folder named after my controller, named after my function , so everything stays in sync...
<div class="formatoLogin modulo">
<?php echo form_open('login/doLogin', array('id'=>'formLogin', 'class'=>'form-signin'))?>
<?php $this->load->view('mod/notificacion')?>
<h1>Acceso Restringido</h1>
<div class="form-group">
<label for="Usuario" class="control-label">Usuario:</label>
<input type="text" name="Usuario" id="Usuario" class="form-control" />
</div>
<div class="form-group">
<label for="Contrasenia" class="control-label">Contraseña:</label>
<input type="password" name="Contrasenia" id="Contrasenia" class="form-control">
</div>
<div class="form-group text-center">
<button class="btn btn-info">Acceder</button>
</div>
<?php if($this->uri->segment(3)=='redirect'){?>
<input type="hidden" name="redirect" value="<?php echo $this->uri->segment(4).'/' . $this->uri->segment(5).'/' . $this->uri->segment(6) ?>">
<?php } ?>
<?php echo form_close()?>
</div>
Do I make sense? I hope it works cause it's saved me tons of includes...
Upvotes: 0
Reputation: 9717
First
create header and footer which consists of bootstrap css and js and put them into a templates folder in your views folder
In controller use them like this to every method:
public function index() {
$data['title'] = 'home';
$this->load->view('templates/bootstrap_header',$data);
$this->load->view('index',$data);
$this->load->view('templates/bootstrap_footer');
}
Upvotes: 2