twitter-bootstrap 将 Twitter Bootstrap 添加到 CodeIgniter?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20843265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 19:36:35  来源:igfitidea点击:

Adding Twitter Bootstrap to CodeIgniter?

codeignitertwitter-bootstrap

提问by user3018715

I have developed website using CodeIgniter that uses MySQL to populate a results page. I would now like to improve all the pages appearances and most places recommend using Bootstrap. I have tried to add Bootstrap to my CodeIgniter project but with no success.

我已经使用 CodeIgniter 开发了使用 MySQL 来填充结果页面的网站。我现在想改进所有页面的外观,大多数地方都推荐使用 Bootstrap。我曾尝试将 Bootstrap 添加到我的 CodeIgniter 项目中,但没有成功。

Does anyone know of an up-to-date guide I could follow to complete this?

有没有人知道我可以遵循的最新指南来完成这个?

Thanks

谢谢

回答by jleft

A simple way would be to use Bootstrap CDN. For CSS, simply include this line in the <head>section of every webpage (somewhere in your view files, depending on how you have structured them):

一种简单的方法是使用Bootstrap CDN。对于 CSS,只需在<head>每个网页的部分中包含此行(在视图文件中的某个位置,取决于您如何构建它们):

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">

Bootstrap's plugins depend on jQuery, so you'll need to include jQuery before Bootstrap's JavaScript:

Bootstrap 的插件依赖于 jQuery,所以你需要在 Bootstrap 的 JavaScript 之前包含 jQuery:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

Simple example page:

简单示例页面:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Your great site!</title>
        <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body>
        <div class="jumbotron">
            <div class="container">
                <h1>Hello, world!</h1>
            </div>
        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    </body>
</html>



Alternatively you could host the files on your web server. Upload the relevant files to a publicly accessible directory. I'm going to assume that they are in an assets folder, in your web root, like this:

或者,您可以在 Web 服务器上托管文件。将相关文件上传到可公开访问的目录。我将假设它们位于您的 web 根目录中的资产文件夹中,如下所示:

+-- public_html
|  +-- index.php
|  +-- assets
|  |  +-- css
|  |  |  +-- boostrap.css
|  |  +-- js
|  |  |  +-- bootstrap.js
|  |  |  +-- jquery.js
|  (other files/directories...)

To include them in your view files, you can link them like this:

要将它们包含在您的视图文件中,您可以像这样链接它们:

<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>">

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

You'll need to have loaded the URL Helperto use the base_url()function.

您需要加载URL Helper才能使用该base_url()功能。

回答by jiraya

First time using PHP CodeIgniter , Bootstrap and Bitnami mampstack. ( All develope code in local notebook)

第一次使用 PHP CodeIgniter、Bootstrap 和 Bitnami mampstack。(本地笔记本中的所有开发代码)

1. To extractthe file CodeIgniter 3.x and Boostrap 3.x(Twitter) Here my directory :

1. 提取文件 CodeIgniter 3.x 和 Boostrap 3.x(Twitter) 这是我的目录:

    /Applications/mampstack-5.4.26-2/apache2/htdocs/TestCoceIginter_Bootstra
    /Applications/mampstack-5.4.26-2/apache2/htdocs/TestCoceIginter_Bootstrap/application
    /Applications/mampstack-5.4.26-2/apache2/htdocs/TestCoceIginter_Bootstrap/assets

2.Modification (Add)

2.修改(添加)

a. application/controller/Welcome.php

一个。应用程序/控制器/Welcome.php

    <?php defined('BASEPATH') OR exit('No direct script access allowed');
    class Welcome extends CI_Controller 
    {
    public function __construct() { 
            parent::__construct();
            $this->load->helper('url');

    public function index(){
            $this->load->view('welcome_message');
            }
    }

b.application/views/welcome_message.php

应用程序/视图/welcome_message.php

    <?php defined('BASEPATH') OR exit('No direct script access allowed');?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>">
    <script type="text/javascript" src="<?php echo base_url("assets/js/jquery.min.js"); ?>"></script>
    <script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script>   
    </head>

回答by Bogdan Alexandru Militaru

If you tried to remove the 'index.php' from url like in the official example then you should try this

如果您尝试像官方示例中那样从 url 中删除“index.php”,那么您应该试试这个

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/ [NC,L,QSA]
</IfModule>

回答by bsquad

Open the config.php in /CodeIgniter/application/configdirectory,

打开/CodeIgniter/application/config目录中的config.php ,

And edit it as:

并将其编辑为:

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