向CodeIgniter添加Twitter Bootstrap? [英] Adding Twitter Bootstrap to CodeIgniter?
问题描述
我开发了使用CodeIgniter的网站,使用MySQL填充结果页面。我现在想改善所有的页面外观,大多数地方建议使用Bootstrap。我试图添加Bootstrap到我的CodeIgniter项目,但没有成功。
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.
有没有人知道最新的指南,我可以按照以完成这个?
Does anyone know of an up-to-date guide I could follow to complete this?
感谢
推荐答案
一个简单的方法是使用 Bootstrap CDN 。对于CSS,只需将这一行包含在每个网页的< head>
部分(视图文件中的某个位置,具体取决于结构化它们的方式):
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):
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
Bootstrap的插件依赖于jQuery,所以你需要在Bootstrap的JavaScript之前加入jQuery:
Bootstrap's plugins depend on jQuery, so you'll need to include jQuery before Bootstrap's JavaScript:
<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>
简单示例页面:
<!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>
或者,您可以在Web服务器上托管文件。将相关文件上传到可公开访问的目录。我将假设他们在一个资产文件夹,在你的web根,像这样:
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:
+-- 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>
您需要加载 URL助手使用 base_url()
函数。
这篇关于向CodeIgniter添加Twitter Bootstrap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!