CodeIgniter不会重定向到控制器,Apache提供404,基本控制器工作

时间:2017-05-31 14:06:15

标签: php apache codeigniter redirect xampp

所以,我想用PHP学习MVC并做了一个简单的项目。

我已经配置了XAMPP和一个重定向到我的项目目录的别名/ gambit,不知道它是否重要。

这是我的控制器users.php:

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

class Users extends CI_Controller 
{
function __construct()
{
    parent::__construct();
    $this->load->library('form_validation');
    $this->load->model('user');
    $this->load->helper('url');

}

public function account()
{
    $data = array();
    if($this->session->userdata('isUserLoggedIn'))
    {
        $data['user'] = $this->user->getRows(array('id'=>$this->session->userdata('userId')));
        $this->load->view('account',$data);
    }
    else
    {
        redirect('login');
    }
}

public function login()
{
    $data=array();
    if($this->session->userdata('success_msg'))
    {
        $data['success_msg'] = $this->session->userdata('success_msg');
        $this->session->unset_userdata('successs_msg');

    }
    if($this->session->userdata('error_msg'))
    {
        $data['error_msg'] = $this->session->userdata('error_msg');
        $this->session->unset_userdata('error_msg');
    }
    if($this->input->post('loginSubmit'))
    {
        $this->form_validation->set_rules('email','Email','required|valid_email');
        $this->form_validation->set_rules('password','Password','required');

        if($this->form_validation->run() == true)
        {
            $con['returnType'] = 'single';
            $con['conditions'] = array(
                'email' =>$this->input->post('email'),
                'password' => md5($this->input->post('password')),
                'status' => '1'
            );

            $checkLogin = $this->user->getRows($con);
            if($checkLogin)
            {
                $this->session->set_userdata('isUserLoggedIn',TRUE);
                $this->session->set_userdata('userId',$checkLogin['id']);
                redirect('account');
            }
            else
            {
                $data['error_msg'] = 'Wrong E-mail or password, please try again.';
            }
        }
    }
    $this->load->view('login', $data);
}

public function registration()
{
    $data = array();
    $userData = array();
    if($this->input->post('regisSubmit'))
    {
        $this->form_validation->set_rules('email','Email','required|valid_email|callback_email_check');
        $this->form_validation->set_rules('password','password','required');
        $this->form_validation->set_rules('conf_password','confirm password','required|matches[password]');

        $userData = array(
            'email' =>strip_tags($this->input->post('email')),
            'password' => md5($this->input->post('password'))
        );

        if($this->form_validation->run() == true)
        {
            $insert = $this->user->insert($userData);
            if($insert)
            {
                $this->session->set_userdata('success_msg','Registration successful! Please, log in');
                redirect ('login');
            }
            else
            {
                $data['error_msg'] = 'An error occured. Please, try again later.';
            }
        }
    }

    $data['user'] = $userData;
    $this->load->view('registration',$data);
}

public function logout()
{
    $this->session->unset_userdata('isUserLoggedIn');
    $this->session->unset_userdata('userId');
    $this->session->sess_destroy();
    $this->load->view('login',$data);
}

public function email_check($str)
{
    $con['returnType'] = 'count';
    $con['conditions'] = array('email'=>$str);
    $checkEmail = $this->user->getRows($con);
    if($checkEmail>0)
    {
        $this->form_validation->set_message('email_check','The given email already exists.');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}

}

函数registration()是有问题的,我希望它在成功注册后重定向到控制器的login()函数,而不是Apache给我错误404对象找不到。

我尝试过登录&#39;,&#39; / login&#39; &#39;用户/登录&#39;等等无济于事

如果我将登录设置为基本控制器,它就像魅力一样。

我在xampp中启用了rewrite_mod,这是我的.htaccess文件

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]

CONFIG.PHP:

$config['index_page'] =  ''; 
$config['uri_protocol'] = "REQUEST_URI"; //tried AUTO too
$config['base_url'] = 'http://localhost/gambit/';

项目结构:

struct

2 个答案:

答案 0 :(得分:0)

mHelper.consumeAsync(inventory.getPurchase(SKU_ITEM), mConsumeFinishedListener);

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
           new IabHelper.OnConsumeFinishedListener() {
    public void onConsumeFinished(Purchase purchase, IabResult result) {
        if (result.isSuccess()) {
            // provision the in-app purchase to the user
            // (for example, credit 50 gold coins to player's character)
        } else {
            // handle error
        }
    }
};

你必须看到敏感案例。

您的控制器文件名&#34;用户&#34;但是你的班级是&#34;用户&#34;。

将您的控制器文件名更改为用户。

希望这个答案可以解决你的问题。

答案 1 :(得分:0)

.htaccess必须是这样的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]