访问CodeIgniter'中的基本url()或站点url();自定义配置文件

访问CodeIgniter'中的基本url()或站点url();自定义配置文件,codeigniter,Codeigniter,我想访问base\u url()方法,以便在自定义配置文件中获取我的应用程序url 我不想写$config['base_url']='some url'在自定义配置文件中。要使用base_url(),必须首先加载url帮助程序。这可以在application/config/autoload.php中完成,然后: $autoload['helper'] = array('url'); 或手动: $this->load->helper('url'); 要打印返回值,请执行以下操作:

我想访问
base\u url()
方法,以便在自定义配置文件中获取我的应用程序url

我不想写
$config['base_url']='some url'在自定义配置文件中。

要使用base_url(),必须首先加载url帮助程序。这可以在
application/config/autoload.php
中完成,然后:

$autoload['helper'] = array('url');
或手动:

$this->load->helper('url');
要打印返回值,请执行以下操作:

echo base_url();

你的问题不清楚,但请提前回答。要启用基本url,请加载

创建自定义配置文件

<?php

// Testing
echo config_item('base_url');

$config['test'] = '111';

您可以使用包含默认加载的所有设置的
$this->config
数组。 例如:您可以创建
sample.php
config文件并将下一个代码放入

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| Sample
| -------------------------------------------------------------------------
|
|
*/

//here you can see how is used base_url value from config.php
$config['r'] = $this->config['base_url'];

试试
$this->config->item('base\u url')
。这不是working@MSaikat首先在autoload.php添加了我的应答器加载url帮助程序。但是在自定义配置文件(config/my_config.php)中使用base_url()时抛出错误,即未定义的方法base_url()
<?php

class Welcome extends CI_Controller {

 public function __construct() {
    parent::__construct();
    $this->load->helper('url');
 }

}
$config['base_url'] = 'http://localhost/project/'; 
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| Sample
| -------------------------------------------------------------------------
|
|
*/

//here you can see how is used base_url value from config.php
$config['r'] = $this->config['base_url'];
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller
{
    public function index()
    {
        var_dump($this->config->item('r'));
    }
}