[英]How to run function of another controller with base_url specified in config.php
I have controller welcome
below that redirect to function of another controller in controllers/auth/login.php
我在下面
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);
}
}
Here, the config.php
: 在这里,
config.php
:
$config['base_url'] = '';
$config['index_page'] = 'index.php';
it work well. 它运作良好。 But when i specified the base_url in config file into:
但是当我在配置文件中指定base_url时:
$config['base_url'] = 'http://localhost/cilog/';
$config['index_page'] = '';
Object not found
. Object not found
。 why it be? 为什么呢? but it work again when i specified
index_page
into index.php
. 但是当我在
index.php
指定index_page
时,它又可以工作了。
I believe this is because of the way CodeIgniter handles it's URL's. 我相信这是因为CodeIgniter处理URL的方式。 I'm not actually sure why Codeigniter does this, but they include
index.php
in there URL. 我实际上不确定为什么Codeigniter会这样做,但是它们在URL中包含
index.php
。
So your URL would look something like http://localhost/cilog/index.php/auth/login
因此,您的网址应类似于
http://localhost/cilog/index.php/auth/login
You can either rewrite your .htaccess
file to remove the index.php
by putting this in: 您可以通过以下方法重写
.htaccess
文件以删除index.php
:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and keep your $config['base_url']
set too "http://localhost/cilog/"
并也将
$config['base_url']
设置为"http://localhost/cilog/"
OR 要么
specify both a $config['base_url']
and $config['index_page']
同时指定
$config['base_url']
和$config['index_page']
See here for more info: http://ellislab.com/codeigniter/user-guide/general/urls.html (Removing the index.php file) 有关更多信息,请参见此处: http : //ellislab.com/codeigniter/user-guide/general/urls.html (删除index.php文件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.