[英]Controller 404 issue in codeigniter
I am trying to call my a controller from another controller using redirect like so.. 我试图像这样使用重定向从另一个控制器中调用我的控制器。
Welcome Controller 欢迎控制器
public function login(){
$rules=array(
array(
'field'=>'username',
'label'=>'Username',
'rules'=>'required|trim'
),
array(
'field'=>'password',
'label'=>'Password',
'rules'=>'trim|required'
),
);
$this->form_validation->set_rules($rules);
if($this->form_validation->run()==TRUE){
$data=array(
'username'=>$this->security->xss_clean($this->input->post('username')),
'password'=>$this->security->xss_clean($this->input->post('password'))
);
$account_details=$this->users_model->getCredentials($data);
if($account_details->num_rows()==1){
$account_details=$account_details->result();
$this->session->set_userdata(array('username'=>$account_details[0]->username));
redirect(site_url('navigation'),'refresh');
}else{
$this->session->set_flashdata('message','Wrong username or password.');
$this->show_login();
}
}else{
$this->session->set_flashdata('error',validation_errors());
$this->show_login();
}
}
Navigation Controller 导航控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Navigation extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model('Users_access_model');
}
public function index(){
$data['links']=$this->Users_access_model->get_links($this->session->userdata['username']);
$this->load->view('common/header');
$this->load->view('common/view_navigation');
$this->load->view('common/scripts');
}
}
?>
this comes out in my addressbar 这出现在我的地址栏中
http://localhost/piercapitan/index.php/navigation
an I get this 我明白了
404 Page Not Found
The page you requested was not found.
This is in my config 这是在我的配置中
$config['base_url'] = 'http://localhost/piercapitan/';
This is my .htaccess 这是我的.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I have used the redirect before but I was using it from my windows machine but when I transferred to Ubuntu, that is the time that I get this issue. 我以前使用过重定向,但是我从Windows机器上使用过重定向,但是当我转移到Ubuntu时,这就是我遇到此问题的时间。 Thank you.
谢谢。
Change from 从
$config['base_url'] = 'http://localhost/piercapitan/';
to 至
$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';
$config['base_path'] = $_SERVER['DOCUMENT_ROOT'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';
Also change from 也从
redirect(site_url('navigation'),'refresh');
to 至
redirect('/navigation','refresh');
or 要么
redirect(base_url('navigation'));
You will need to autoload the url helper in the file 'application/config/autoload.php' 您将需要在文件“ application / config / autoload.php”中自动加载网址帮助器
$autoload['helper'] = array('url');
just try this in 尝试一下
application/config/config.php
application / config / config.php
$config ['index_page'] = '';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.