控制器404在codeigniter中发布

时间:2016-12-31 09:50:16

标签: php codeigniter

我试图使用像这样的重定向从另一个控制器调用我的控制器..

欢迎控制器

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();
    }
}

导航控制器

<?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');
    }
    }

     ?>

这在我的地址栏中显示

http://localhost/piercapitan/index.php/navigation

我得到了这个

404 Page Not Found

The page you requested was not found.

这是我的配置

$config['base_url'] = 'http://localhost/piercapitan/';

这是我的.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

之前我使用过重定向,但是我从我的Windows机器上使用它,但是当我转移到Ubuntu时,那是我得到这个问题的时间。谢谢。

2 个答案:

答案 0 :(得分:1)

改变
$config['base_url'] = 'http://localhost/piercapitan/';

$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'])) . '/';

也可以从

更改
redirect(site_url('navigation'),'refresh');

redirect('/navigation','refresh'); 

redirect(base_url('navigation'));

您需要在文件&#39; application / config / autoload.php&#39;

中自动加载网址帮助器
$autoload['helper'] = array('url');

答案 1 :(得分:0)

只需在

中试一试
  

应用/配置/ config.php中

$config ['index_page'] = '';