繁体   English   中英

PHP:带有CodeIgniter控制器功能的404

[英]PHP: 404 with CodeIgniter controller function

在学习CodeIgniter时,我在遵循本教程的过程中遇到了障碍。 调用“ Main ”类控制器的“ login_validation ”函数时,我找不到404。

在此服务器上找不到请求的URL / ci / main / login_validation。

“主”控制器的类和功能

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

class Main extends CI_Controller {

    public function index() {
        $this->login();
    }

    public function login() {
        $this->load->view('login');
    }

    public function login_validation() {   // NOT FOUND?
        $this->load->library('form_validation');
        $this->form_validation->set_rules('email','Email','required');
        $this->form_validation->set_rules('password','Password','required|md5'); //md5 value encryption

        echo "ok"; //check if function executes

        if ($this->form_validation->run()) {
            redirect('main/members');
        } else {
            $this->load->view('login');
        }
    }

}

View PHP文件中的相关代码

<?php 

    echo form_open('main/login_validation');  // NOT FOUND?

    echo validation_errors();

    echo "<p>Email: ";
    echo form_input('email');
    echo "</p>";

    echo "<p>Password: ";
    echo form_password('password');
    echo "</p>";

    echo "<p>";
    echo form_submit('login_submit','Login');
    echo "</p>";

    echo form_close();

?>

.htaccess代码

目录在本地主机上

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/ci/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule> 

在以下代码中使用.htaccess

Options +FollowSymLinks
#IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM