Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate Bootstrap on CodeIgniter

I'm trying to use bootstrap on a codeigniter web but it looks like the bootstrap files are not found

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="<?php echo base_url('application/bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="<?php echo base_url('application/bootstrap/js/bootstrap.min.js');?>"></script>

I've checked the paths generated by base_url() and it are correct.

like image 415
AFS Avatar asked Apr 22 '15 10:04

AFS


People also ask

Can I use Bootstrap with PHP?

PHP is a server-side programming language, which means that you will need a local server to run PHP code. Developers who use Bootstrap with PHP will be able to enjoy plenty of benefits. Here is a step-by-step guide on how you can use the Bootstrap framework with PHP.

What is Bootstrap integration?

Bootstrap is a free front-end framework for faster and easier web development. Bootstrap includes HTML and CSS based design templates for typography, forms, buttons, tables, navigation, modals, image carousels and many other, as well as optional JavaScript plugins.

How do I link Bootstrap to CSS?

How to Use Bootstrap CSS. In order to use Bootstrap CSS, you need to integrate it into your development environment. To do that, you simply need to create a folder on your computer. In that folder, save your compiled CSS and JS files and a new HTML file where you'll load Bootstrap.


2 Answers

move bootstrap folder on root location, because CI is understanding application folder as controller although application folder is restricted from client request by /application/.htaccess file

|-
   |-application
   |-bootstrap

//and use path as
<?php echo base_url('bootstrap/css/bootstrap.min.css');?>
like image 106
Girish Avatar answered Sep 28 '22 08:09

Girish


  1. Create a folder(assets) in Codeigniter root directly (Same level to application folder)

  2. Paste your bootstrap files into that folder

  3. add link code in your view file

    <link type="text/css" href="<?= base_url(); ?>assets/bootstrap.min.css" rel="stylesheet">
    
  4. add this line in your controller file application/cotrollers/test.php

    <?php
    class Test extends CI_Controller {
    
    public function index()
      {
       $this->load->helper('url'); // Load url links
       $this->load->view('index'); //Load view page
      }
    
    }
    ?>
    
  5. Now you can use bootstrap classes in your view
like image 22
Senthoo Avatar answered Sep 28 '22 07:09

Senthoo