Bootstrap文件不能在其他代码页中正确加载 [英] Bootstrap files not load properly in other codeigniter pages

查看:139
本文介绍了Bootstrap文件不能在其他代码页中正确加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

加载视图文件从索引函数它没有问题,加载引导文件。

load view file from index function it there no problem to load bootstrap files.

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



当我尝试从其他函数加载视图时,

When I try to load the view from other functions, then the bootstrap files does not load properly.

public function fun_one()
{
    $this->load->view('page_one');      
} 


推荐答案

资源的网址。
我可以建议两种方法来解决此问题:

It seems you are using relative URLs for your assets. I could suggest two ways to resolve this issue:


  • 使用HTML < base& / code>元素指定所有相对网址的基本网址。

  • 对资产使用绝对网址。

您可以使用HTML < base> c> c / c>中设置 href 属性, > base_url() function:

You could use the HTML <base> element in the <head>, and set the href attribute by using CodeIgniter base_url() function:

<base href="<?php echo base_url(); ?>">

然后所有相对URL使用 href 属性作为基本URL地址。

Then all the relative URLs use this href attribute as the base URL address.

使用< base> 的潜在缺点是它会影响锚

The potential disadvantage of using <base> is that it affects the anchor tags as well.

在此方法中,您需要添加 base_url()到每个资产的URL地址。例如:

In this approach, you need to add the base_url() to each assets' URL address. For instance:

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

这篇关于Bootstrap文件不能在其他代码页中正确加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆