base_url() 函数在 codeigniter 中不起作用 [英] base_url() function not working in codeigniter

查看:30
本文介绍了base_url() 函数在 codeigniter 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 web 应用程序中使用 codeigniter.我正在尝试使用 base_url() 函数,但它显示空结果.我还通过自动加载文件使用了自动加载助手,但它似乎也不起作用.我也定义了基本常量,但都是徒劳的.

In my web application using codeigniter. I am trying to use base_url() function but it shows empty results. I have also used autoload helper through autoload file, but then too it doesn't seem to work. Also I had defined base constants but all in vain.

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title><?php echo $title; ?></title>        
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />
        <script type="text/javascript">
            //<![CDATA[
            base_url = '<?= base_url();?>';
            //]]>
        </script>
    </head>

推荐答案

为了使用 base_url(),您必须首先加载 URL Helper.这可以在 application/config/autoload.php 中完成(在第 67 行或附近):

In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php (on or around line 67):

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

或者,手动:

$this->load->helper('url');

一旦加载,请务必记住 base_url() 不会隐式打印或回显任何内容,而是返回要打印的值:

Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:

echo base_url();

还要记住,返回的值是配置文件中提供的站点的基本 URL.CodeIgniter 也会在配置文件中容纳一个空值:

Remember also that the value returned is the site's base url as provided in the config file. CodeIgniter will accomodate an empty value in the config file as well:

如果这个 (base_url) 没有设置,那么 CodeIgniter 会猜测你安装的协议、域和路径.

application/config/config.php,第 13 行

application/config/config.php, line 13

这篇关于base_url() 函数在 codeigniter 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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