php 在 CodeIgniter 上集成 Bootstrap
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29794513/
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
Integrate Bootstrap on CodeIgniter
提问by AFS
I'm trying to use bootstrap on a codeigniter web but it looks like the bootstrap files are not found
我正在尝试在 codeigniter 网络上使用引导程序,但似乎找不到引导程序文件
<!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.
我检查了 base_url() 生成的路径,它是正确的。
回答by Girish
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
移动bootstrap
文件夹根目录的位置,因为CI是理解application
文件夹中controller
,虽然应用程序文件夹是从由客户机请求的限制/application/.htaccess
文件
|-
|-application
|-bootstrap
//and use path as
<?php echo base_url('bootstrap/css/bootstrap.min.css');?>
回答by lightup
Don't forget to include the CodeIgniter URL helper in your controller
不要忘记在控制器中包含 CodeIgniter URL 助手
$this->load->helper('url');
回答by ACV
Here's the best guide I've found so far: How to include bootstrap in CI
这是迄今为止我找到的最好的指南: 如何在 CI 中包含引导程序
In short:
简而言之:
Download bootstrap
Put it in an assets folder on same level as application folder
Also put jquery
Include css in header and jquery in footer of your templates:
下载引导程序
将它放在与应用程序文件夹相同级别的资产文件夹中
也把jquery
在模板的页眉和 jquery 中包含 css:
<html> <head> <title>CodeIgniter Tutorial</title> <link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>" /> </head> <body> <h1>H_E_A_D_E_R</h1>
<html> <head> <title>CodeIgniter Tutorial</title> <link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>" /> </head> <body> <h1>H_E_A_D_E_R</h1>
and :
和 :
<hr/>
<em>© 2016</em>
<script type="text/javascript" src="<?php echo base_url("assets/js/jquery-3.1.1.js"); ?>"></script>
<script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script>
</body>
</html>
回答by William Kheng
Just sharing over here so that you no need to combine folders manually. I used this package offered from github regularly to commit new projects. Of course you will have to modify the application/config/config.php to get things work !
只需在这里共享,这样您就无需手动组合文件夹。我经常使用 github 提供的这个包来提交新项目。当然,您必须修改 application/config/config.php 才能使事情正常运行!
https://github.com/sjlu/CodeIgniter-Bootstrap
https://github.com/sjlu/CodeIgniter-Bootstrap
Cheers !
干杯!
回答by Senthoo
Create a folder(assets) in Codeigniter root directly (Same level to application folder)
Paste your bootstrap files into that folder
add link code in your view file
<link type="text/css" href="<?= base_url(); ?>assets/bootstrap.min.css" rel="stylesheet">
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 } } ?>
- Now you can use bootstrap classes in your view
直接在 Codeigniter 根目录中创建一个文件夹(资产)(与应用程序文件夹级别相同)
将引导程序文件粘贴到该文件夹中
在您的视图文件中添加链接代码
<link type="text/css" href="<?= base_url(); ?>assets/bootstrap.min.css" rel="stylesheet">
在您的控制器文件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 } } ?>
- 现在您可以在视图中使用引导程序类
回答by sharif pilot
- Download the Bootstrap file from the internet if you want to work offline
- Unzip and rename and copy to root folder. If you put it in application folder, .htaccess will not allow it to be accessed.
Add the link like the following line of code:
<link href="<?php echo base_url('assets/css/bootstrap.min.css');?> rel="stylesheet">
- 如果您想离线工作,请从 Internet 下载 Bootstrap 文件
- 解压并重命名并复制到根文件夹。如果你把它放在应用程序文件夹中,.htaccess 将不允许它被访问。
添加链接,如以下代码行:
<link href="<?php echo base_url('assets/css/bootstrap.min.css');?> rel="stylesheet">