函数在codeigniter中不起作用

时间:2022-10-22 13:30:07

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.

我正在开发一个使用codeigniter的we应用程序。我试图使用base_url()函数,但它显示的是空结果。我已经通过autoload文件使用了autoload助手,但它似乎也不起作用。我也定义了基本常数,但都是徒劳的。请帮助。

<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>

7 个解决方案

#1


129  

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):

为了使用base_url(),您必须首先加载URL Helper。这可以在应用程序/配置/自动加载中完成。php(在或在第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:

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

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:

还要记住,返回的值是配置文件中提供的站点的基本url。CodeIgniter将在配置文件中包含一个空值:

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

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

application/config/config.php, line 13

应用程序/配置/配置。php,13号线

#2


4  

If you want to use base_url(), so we need to load url helper.

如果您想使用base_url(),那么我们需要加载url helper。

  1. By using autoload $autoload['helper'] = array('url');
  2. 通过使用autoload $autoload['helper'] =数组('url');
  3. Or by manually load in controller or in view $this->load->helper('url');
  4. 或通过手动加载控制器或视图$this->load->助手(“url”);

Then you can user base_url() anywhere in controller or view.

然后可以在控制器或视图的任何位置使用base_url()。

#3


2  

Check if you have something configured inside the config file /application/config/config.php e.g.

检查配置文件/应用程序/配置/配置中是否配置了某些内容。php。

$config['base_url'] = 'http://example.com/';

#4


2  

I think you haven't edited codeigniter files to enable base_url(). you try to assign it in url_helper.php you also can do the same config/autoload.php file. you can add this code in your autoload.php

我认为您还没有编辑codeigniter文件来启用base_url()。您尝试在url_helper中分配它。php也可以进行相同的配置/自动加载。php文件。您可以在autoload.php中添加此代码

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

Than You will be able to ue base_url() like this

这样就可以使用base_url()

<link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />

#5


0  

If you don't want to use the url helper, you can get the same results by using the following variable:

如果您不想使用url helper,您可以使用以下变量获得相同的结果:

$this->config->config['base_url']

It will return the base url for you with no extra steps required.

它将为您返回基本url,不需要额外的步骤。

#6


0  

First of all load URL helper. you can load in "config/autoload.php" file and add following code $autoload['helper'] = array('url');

首先加载URL助手。您可以加载“config/autoload”。php“文件,添加以下代码$autoload['helper'] =数组('url');

or in controller add following code

或者在控制器中添加以下代码

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

then go to config.php in cofig folder and set

然后去配置。php在cofig文件夹和设置中

$config['base_url'] = 'http://urlbaseurl.com/';

hope this will help thanks

希望这对您有所帮助

#7


0  

First of all you must load the url helper file to your project

首先,必须将url助手文件加载到项目中。

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

Then you will get base_url by

然后您将获得base_url by

echo base_url();

Read more about base_url here

在这里阅读更多关于base_url的信息

#1


129  

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):

为了使用base_url(),您必须首先加载URL Helper。这可以在应用程序/配置/自动加载中完成。php(在或在第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:

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

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:

还要记住,返回的值是配置文件中提供的站点的基本url。CodeIgniter将在配置文件中包含一个空值:

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

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

application/config/config.php, line 13

应用程序/配置/配置。php,13号线

#2


4  

If you want to use base_url(), so we need to load url helper.

如果您想使用base_url(),那么我们需要加载url helper。

  1. By using autoload $autoload['helper'] = array('url');
  2. 通过使用autoload $autoload['helper'] =数组('url');
  3. Or by manually load in controller or in view $this->load->helper('url');
  4. 或通过手动加载控制器或视图$this->load->助手(“url”);

Then you can user base_url() anywhere in controller or view.

然后可以在控制器或视图的任何位置使用base_url()。

#3


2  

Check if you have something configured inside the config file /application/config/config.php e.g.

检查配置文件/应用程序/配置/配置中是否配置了某些内容。php。

$config['base_url'] = 'http://example.com/';

#4


2  

I think you haven't edited codeigniter files to enable base_url(). you try to assign it in url_helper.php you also can do the same config/autoload.php file. you can add this code in your autoload.php

我认为您还没有编辑codeigniter文件来启用base_url()。您尝试在url_helper中分配它。php也可以进行相同的配置/自动加载。php文件。您可以在autoload.php中添加此代码

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

Than You will be able to ue base_url() like this

这样就可以使用base_url()

<link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />

#5


0  

If you don't want to use the url helper, you can get the same results by using the following variable:

如果您不想使用url helper,您可以使用以下变量获得相同的结果:

$this->config->config['base_url']

It will return the base url for you with no extra steps required.

它将为您返回基本url,不需要额外的步骤。

#6


0  

First of all load URL helper. you can load in "config/autoload.php" file and add following code $autoload['helper'] = array('url');

首先加载URL助手。您可以加载“config/autoload”。php“文件,添加以下代码$autoload['helper'] =数组('url');

or in controller add following code

或者在控制器中添加以下代码

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

then go to config.php in cofig folder and set

然后去配置。php在cofig文件夹和设置中

$config['base_url'] = 'http://urlbaseurl.com/';

hope this will help thanks

希望这对您有所帮助

#7


0  

First of all you must load the url helper file to your project

首先,必须将url助手文件加载到项目中。

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

Then you will get base_url by

然后您将获得base_url by

echo base_url();

Read more about base_url here

在这里阅读更多关于base_url的信息