如何在codeigniter中包含bootstrap模板

时间:2016-08-06 07:53:14

标签: codeigniter

我想在codeigniter代码中包含一个bootstrap模板,所以我将模板包含在views文件夹中然后我在控制器中调用它但我在页面中看不到模板

这是我的代码:

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootsrtap Free Admin Template - SIMINTA | Admin Dashboad Template</title>
    <!-- Core CSS - Include with every page -->
    <link href="plugins/bootstrap/bootstrap.css" type="text/css" rel="stylesheet" />
    <link href="font-awesome/css/font-awesome.css" type="text/css" rel="stylesheet" />
    <link href="plugins/pace/pace-theme-big-counter.css" type="text/css" rel="stylesheet" />
    <link href="css/style.css" type="text/css" rel="stylesheet" />
    <link href="css/main-style.css" type="text/css" rel="stylesheet" />

</head>

<body class="body-Login-back">

    <div class="container">

        <div class="row">
            <div class="col-md-4 col-md-offset-4 text-center logo-margin ">
              <img src="img/logo.png" alt=""/>
                </div>
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">                  
                    <div class="panel-heading">
                        <h3 class="panel-title">Please Sign In</h3>
                    </div>
                    <div class="panel-body">
                        <form role="form">
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="Password" name="password" type="password" value="">
                                </div>
                                <div class="checkbox">
                                    <label>
                                        <input name="remember" type="checkbox" value="Remember Me">Remember Me
                                    </label>
                                </div>
                                <!-- Change this to a button or input when using this as a form -->
                                <a href="index.html" class="btn btn-lg btn-success btn-block">Login</a>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

     <!-- Core Scripts - Include with every page -->
    <script src="plugins/jquery-1.10.2.js"></script>
    <script src="plugins/bootstrap/bootstrap.min.js"></script>
    <script src="plugins/metisMenu/jquery.metisMenu.js"></script>

</body>

</html>

这是login.php(在views文件夹中)

---------------

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootsrtap Free Admin Template - SIMINTA | Admin Dashboad Template</title>
    <!-- Core CSS - Include with every page -->


</head>

控制器

<?php if ( ! defined('BASEPATH')) exit('No direct access allowed');


class Login extends CI_Controller

{

    public function index()

    {   
            $this->load->view('login');

    }



}

这是login.php(在controllers文件夹中)

请帮我解决这个问题

2 个答案:

答案 0 :(得分:2)

首先,您应该将所有资产都放在应用程序文件夹的旁边。

因为应用程序文件夹中的.htaccess文件阻止

project > 
project > application
project > assets
project > system
project > index.php
project > .htaccess <!-- use a htaccess here for removing index.php

第二次在config&gt;中设置你的base_url的config.php

// You are recommend to do so in CI 3 + versions

$config['base_url'] = 'http://localhost/yourprojectname/';

第三次自动加载网址助手配置&gt; autoload.php

$autoload['helper'] = array('url');
  

控制器确保您的文件名首字母仅限于上限   情况下

如上所述http://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world

文件名Example.php

<?php

class Example extends CI_Controller {

    public function index() {

        $this->load->view('header');
        $this->load->view('example');
        $this->load->view('footer');

    }

}

然后创建一个header.php和footer.php以及example.php视图

http://www.codeigniter.com/user_guide/general/views.html#loading-multiple-views

header.php视图

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/bootstrap/css/bootstrap.css');?>">
</head>
<body>

example.php view

Any content you need

footer.php视图

<script type="text/javascript" src="<?php echo base_url('assets/bootstrap/js/bootstrap.js');?>"></script>
</body>
</html>

答案 1 :(得分:0)

enter image description here

这是一个例子。创建一个名为assets的文件夹,将所有样式,js资源粘贴到其中。

请显示控制台日志选项卡。例如:

enter image description here