[英]Base_url() not working on codeigniter
I am using CodeIgniter bootstrap stylesheet link URL can't work properly. 我正在使用CodeIgniter引导程序样式表链接URL不能正常工作。 Controller code
控制器代码
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->helper('url');
$data['title'] = "Login Home";
$this->load->view('home',$data);
}
}
HTML Code HTML代码
<div class="container">
<div class="row">
<div class="col-lg-offset-4 col-lg-4">
<div class="well">
<h3>welcome</h3>
</div>
</div>
</div>
</div>
CSS link code CSS链接代码
<link href="<?php echo base_url("register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">
Place assets out side of application .
将资产放在应用程序之外 。 Reason the .htaccess in application folder blocks it.
原因是应用程序文件夹中的.htaccess阻止了它。
application
assets
assets > bootstrap > css > bootstrap.css
assets > bootstrap > js > bootstrap.js
system
index.php
First I would suggest 首先我建议
config/autoload.php config / autoload.php
$autoload['helper'] = array('url');
then 然后
config/config.php Set your base url config / config.php设置您的基本网址
$config['base_url'] = 'http://localhost/projectnmame/';
in config.php set this line 在config.php中设置这一行
$config['base_url'] = 'http://localhost/register/';
root directory set this way 根目录这样设置
application
system
bootstrap-3.3.6
ensure that you are using .htaccess file in your codeigniter application.create one folder assets.place your css file in assets folder.after that link that file like this, 确保您在codeigniter应用程序中使用.htaccess文件。创建一个文件夹素材资源。将css文件放在素材资源文件夹中。
in application folder config file paste this, 在应用程序文件夹配置文件中将其粘贴,
$root = 'http://' . $_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);;
$config['base_url'] = $root;
<link href="<?php echo base_url("assets/register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">
if you are not using htaccess file, 如果您没有使用htaccess文件,
<link href="<?php echo base_url("index.php/assets/register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">
try this.... 尝试这个....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.