提交表单时找不到codeigniter 404

时间:2015-10-24 10:38:25

标签: php forms codeigniter submit http-status-code-404

我知道这个问题已被问过一千次,但我真的尝试了,但我没有成功解决这个问题。

所以当我提交我的注册表时,我收到了404错误,但控制器/功能路径是正确的,所以我不明白为什么会出现这个错误。

报名表:

<section class='container'>
<?php 
$this->load->helper('form');
$this->load->helper('captcha');

$attributs = array('class' => 'col-md-12 col-xs-12', 'id' => 'inscription');
echo form_open('AjouterUtilisateur/ajouter', $attributs);
echo "Nom <br>".form_input('nom','test')."<br>";
echo "Prénom <br>".form_input('prenom','test')."<br>";
echo "Age <br>".form_input('age','test')."<br>";
echo "Pseudo <br>".form_input('pseudo','test')."<br>";
echo "Email <br>".form_input('email','test')."<br>";
echo "Mot de passe <br>".form_password('mdp','test')."<br>";
echo "Confirmation <br>".form_password('mdpConf','test')."<br>";
$bouton = array(
    'name' => 'button',
    'class' => 'button'
);
echo "<br>".form_submit($bouton, 'Valider !');
echo form_close();
?>
</section>

添加控制器:

class AjouterUtilisateur extends Utilisateur
{
    public function __construct()
    {
        parent::__construct();
        $this->Pseudo=$_POST['pseudo'];
        $this->Email=$_POST['email'];
        $this->Nom=$_POST['nom'];
        $this->Prenom=$_POST['prenom'];
        $this->Age=$_POST['age'];
        $this->MDP=$_POST['mdp'];

        $this->load->database();
    }

    public function __destruct()
    {
        $this->db->close();
    }

    public function ajouter()
    {
        $donnees= array('Nom' => $Nom, 'Prenom' => $Prenom, 'Age' => $Age, 'Pseudo' => $Pseudo,'Email' => $Email, 'MDP' => $MDP,);
        $req = $this->db->insert_string('utilisateurs', $donnees);
        $query = $this->db->query('$req');
        if($query==FALSE)
            redirect(base_url('/pages/err'), 'refresh');
        else
            redirect(base_url('/pages/accueil'), 'refresh');
    }
}

1 个答案:

答案 0 :(得分:0)

好的,所以我按照你的所有提示(tahnks for that;))并知道我有“Class'MY_Utilisateur'找不到”错误,我看不出我做错了什么。

在core / MY_Utilisateur

class MY_Utilisateur extends CI_Controller{
    protected $ID;
    protected $Pseudo;
    protected $Email;
    protected $Nom;
    protected $Prenom;
    protected $Age;
    protected $MDP;
    protected $DateInscription;

    public function __construct()
    {
        parent::__construct();
    }
}

在controllers / Ajouterutilisateur.php中:

class Ajouterutilisateur extends MY_Utilisateur
{
    public function __construct()
    {
        parent::__construct();
        $this->Pseudo=$_POST['pseudo'];
        $this->Email=$_POST['email'];
        $this->Nom=$_POST['nom'];
        $this->Prenom=$_POST['prenom'];
        $this->Age=$_POST['age'];
        $this->MDP=$_POST['mdp'];

        $this->load->database();
    }

    public function __destruct()
    {
        $this->db->close();
    }

    public function ajouter()
    {
        $donnees= array('Nom' => $Nom, 'Prenom' => $Prenom, 'Age' => $Age, 'Pseudo' => $Pseudo,'Email' => $Email, 'MDP' => $MDP,);
        $req = $this->db->insert_string('utilisateurs', $donnees);
        $query = $this->db->query('$req');

        if($query==FALSE)
            redirect(base_url('/pages/err'), 'refresh');
        else
            redirect(base_url('/pages/accueil'), 'refresh');
    }
}