简体   繁体   English

Codeigniter-404发送数据到控制器

[英]Codeigniter - 404 in send data to controller

Form 形成

<?php echo validation_errors(); ?>
   <?php $attributes = array('class' => 'navbar-form pull-right');
      echo form_open('login/checkLogin', $attributes); ?>
       <input class="span2" type="text" placeholder="Username" name="username">
       <input class="span2" type="password" placeholder="Password" name="password">
       <button type="submit" class="btn">Sign in</button>
</form>

Contorller 控制器

<?php

class Login extends CI_Controller{  

    public function index(){
        $this->load->view('templates/menu');
    }
    public function checkLogin(){        
        $this->form_validation->set_rules('username', 'Username', 'required|callback_verifyUser');
        $this->form_validation->set_rules('password', 'Password', 'required|callback_verifyPassword');

        if($this->form_validation->run() == false){
            $this->load->view('pages/error');
        }else{

        }
    }
}
?>

Model 模型

<?php

class Login_model extends CI_Model{
    public function login($name, $pass){
        $this->db->select('name, pass');
        $this->db->from('members');
        $this->db->where('name', $name);
        $this->db->where('pass', $pass);

        $query = $this->db->get();

        if($query->num_rows() == 1){
            return true;
        }else{
            return false;
        }
    }
}
?>

Structure 结构体

application 应用

  • controllers 控制器
    • login.php login.php
  • views 意见
    • templates 范本
      • menu.php menu.php

.htaccess .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !f
RewriteCond %{REQUEST_FILENAME} !d
RewriteRule .* index.php/$0 [PT,L]

My form is located in menu.php, when i push submit return 404 If needed more info please ask me. 我的表单位于menu.php中,当我推送提交返回404时。如果需要更多信息,请询问我。

check your .htaccess & php.ini files. 检查您的.htaccessphp.ini文件。 Look at your mod_rewrite .. Make sure those are configured correctly and that you are not 404 accidentally on extensions. 查看您的mod_rewrite ..确保正确配置了这些文件,并且您在扩展名上没有出现404错误。

Also try instead of 也尝试代替

 if($this->form_validation->run() == false){
        $this->load->view('pages/error');
    }

try 尝试

 if(!$this->form_validation->run()){
 $this->load->view('pages/error');
}

first make sure you have mod_rewrite enabled using phpinfo(); 首先确保您使用phpinfo();启用了mod_rewrite phpinfo(); in some view, then use this: 在某些视图中,请使用以下命令:

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

Here my solution: 这是我的解决方案:

routes.php routes.php

$route['templates/menu'] = 'login/checkLogin';

menu.php menu.php

echo form_open('templates/menu', $attributes);

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

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