如何使用config.php中指定的base_url运行另一个控制器的函数
我有一个控制器如何使用config.php中指定的base_url运行另一个控制器的函数,php,codeigniter,config,base-url,Php,Codeigniter,Config,Base Url,我有一个控制器welcome,它重定向到controllers/auth/login.php中另一个控制器的函数 function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->library('tank_auth'); } function index() { if (!$this->tank_auth->is
welcome
,它重定向到controllers/auth/login.php中另一个控制器的函数
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth');
}
function index() {
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->load->view('welcome', $data);
}
}
在这里,config.php
:
$config['base_url'] = '';
$config['index_page'] = 'index.php';
它工作得很好。但当我将配置文件中的base_url指定为:
$config['base_url'] = 'http://localhost/cilog/';
$config['index_page'] = '';
未找到对象
。为什么会这样?但当我将index\u页面
指定为index.php
时,它又能工作了。我相信这是因为CodeIgniter处理其URL的方式。我不确定Codeigniter为什么会这样做,但它们在URL中包含了index.php
所以你的URL看起来像http://localhost/cilog/index.php/auth/login
您可以重写.htaccess
文件以删除index.php
,方法是将其放入:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
并将您的$config['base\u url']
也设置为”http://localhost/cilog/“
或
指定$config['base\u url']
和$config['index\u page']
有关更多信息,请参见此处:(删除index.php文件)