简体   繁体   English

php codeigniter base_url 不起作用

[英]php codeigniter base_url not working

I am currently using codeigniter to write out templates for a website.我目前正在使用 codeigniter 为网站编写模板。 The problem is that I'm trying to achieve absolute paths for attributes such as href and src , but they aren't working.问题是我试图为hrefsrc等属性实现绝对路径,但它们不起作用。 I've checked my results, and the link's and scripts point through the correct directory, so I'm not sure why there is a problem.我检查了我的结果,链接和脚本指向正确的目录,所以我不确定为什么会出现问题。

This is the code I'm using below:这是我在下面使用的代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Home</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">

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

        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
            <script src="<?php echo base_url() . "assets/html5shiv/html5shiv.js"; ?>"></script>
        <![endif]-->

        <!-- Fav and touch icons go here -->


    </head>
<body>
    <p>This comes from the header view.</p>

    <button class="btn btn-primary">Primary</button>
    <br />
    <a class="btn btn-primary">Secondary</a>

I can tell that this isn't working because I'm trying to use bootstrap to style two buttons, but they aren't working.我可以说这不起作用,因为我正在尝试使用引导程序来设置两个按钮的样式,但它们不起作用。 Can someone please help me figure this out?有人可以帮我解决这个问题吗?

Oh, by the way..my base_url is http://localhost/ProjectName/ , and I know that I have this working correctly because I have enabled the URL helper and I am able to echo the base_url.哦,顺便说一下..我的 base_url 是http://localhost/ProjectName/ ,我知道我可以正常工作,因为我启用了 URL 帮助程序并且我能够回显 base_url。

Please make sure that You've loaded URL helper, in your autoload.php, and also make sure that you've added defined base_url in your config.php.请确保您已在 autoload.php 中加载了 URL helper,并确保您已在 config.php 中添加了定义的 base_url。 if not then this should help you out.如果没有,那么这应该可以帮助您。

I think you haven't edited codeigniter files to enable base_url() .我认为您还没有编辑 codeigniter 文件来启用base_url() you try to assingn it in url_helper.php you also can do the same config/autoload.php file.您尝试在 url_helper.php 中分配它,您也可以执行相同的 config/autoload.php 文件。 you can add this code in your autoload.php您可以在 autoload.php 中添加此代码

$autoload['helper'] = array('url');

There's no need to drop in and out of PHP.无需进出 PHP。 You can just do this:你可以这样做:

     <link rel="stylesheet" href="/assets/bootstrap/css/bootstrap.css" />

if this doesn't work there's a problem with where your css files are.如果这不起作用,则说明您的 css 文件所在的位置有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM