函数在codeigniter中不工作

函数在codeigniter中不工作

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

问题描述

我正在使用codeigniter开发一个我们的应用程序。我试图使用base_url()函数,但它显示空的结果。我已经使用自动加载助手通过自动加载文件,但后来它似乎没有工作。我也定义了基本常数,但都是徒劳的。请帮助。

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


解决方案

为了使用 base_url (),您必须首先加载URL助手。这可以在 application / config / autoload.php (在第67行或其后)执行:

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

或者,手动:

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

一旦载入,请务必记住 base_url / code>不会隐式打印或回显任何东西,而是返回要打印的值:

  base_url(); 

还记得返回的值是配置文件中提供的网站的基本网址。 CodeIgniter也将在配置文件中包含一个空值:



如果这个(base_url)没有设置,CodeIgniter会猜测

application / config / config.php,第13行



I am developing a we application using codeigniter. I am trying to use base_url() function but it shows empty results. I have 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. Please help.

<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>
解决方案

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');

Or, manually:

$this->load->helper('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();

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:

If this (base_url) is not set then CodeIgniter will guess the protocol, domain and path to your installation.

application/config/config.php, line 13

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

09-05 05:18