1

所以,我要做的就是从表单输入向数据库提交一些值。

我有一个控制器clientcreation.php

<?php

class Clientcreation extends CI_Controller
{
  function index(){
     $this->load->view('files/header',$clientRegistration);
     $this->load->view('files/navigation');
     $this->load->view('pages/clientcreation');
     $this->load->view('files/footer');

    ## validation rules here working fine.

     $this->form_validation->set_rules($RegistrationRequiredFields);
        ## Perform Validation
        if ($this->form_validation->run() == FALSE){
             echo validation_errors();             ## show the errorneous fields
        }

    else{
            #### load :: models
            $this->load->model('pages/clientcreationmodel','',TRUE);
                ## get [hashed] inputted pass and submit.
                $this->Clientcreationmodel->hashed_client_pass_and_submit();
            # then, load success page:
            $this->load->view('pages/success/clientRegistrationSuccess');
    }



  }

}

一个模型clientcreationmodel.php

<?php
class Clientcreationmodel extends CI_Model{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function hashed_client_pass_and_submit(){
        ## create hashed version of client inputted [pass]
    /*    
        $initialVal = $_POST['pass'];
        $HashedPassVal = hash('sha512', $initialVal);
        $SaltValue = mcrypt_create_iv(10, MCRYPT_DEV_URANDOM);
        $finalHashedValue = $HashedPassVal.$SaltValue;
    */    
        ## process and insert into db
        $this->input->post('email', TRUE);     
        $this->input->post('pass', TRUE);
        $this->input->post('fname', TRUE);
        $this->input->post('lname', TRUE);
        $this->input->post('title', TRUE);
        $this->input->post('co', TRUE);
        $this->input->post('phone', TRUE);
        $this->input->post('state', TRUE);  
        $this->input->post('numapps', TRUE);
        $this->input->post('versCntrl', TRUE);
        $this->input->post('testFreq', TRUE);
        $this->input->post('submit');

        $this->db->insert('client', $this);
   }

}
?>

一个视图clientcreation.php

<?php
    echo form_open('index/pages/clientcreation',$CustCreationFormAttr);
    echo form_label('Email: ','email');
        echo form_input($CustCreationEmail);echo '<br>';
    echo form_label('Password: ', 'pass');echo '<br>';
        echo form_password($CustCreationPassword);echo '<br>';
    echo form_label('Password Confirm: ', 'passConf');echo '<br>';
        echo form_password($CustCreationConfPassword);echo '<br>';
    echo form_label('First Name: ','fname');echo '<br>';
            echo form_input($CustCreationFirstName);echo '<br>';
    echo form_label('Last Name: ','lname');echo '<br>';
            echo form_input($CustCreationLastName);echo '<br>';
    echo form_label('Title: ', 'title');echo '<br>';
            echo form_input($CustCreationClientTitle);echo '<br>';
    echo form_label('Company: ', 'co');echo '<br>';
            echo form_input($CustCreationCompany);echo '<br>';
        echo form_label('Phone: ','phone');echo '<br>';
            echo form_input($CustCreationPhone);echo '<br>';
    echo form_label('State: ','state');echo '<br>';
            echo form_dropdown('states',$CustCreationState,'Alabama');echo '<br>';
    echo form_label('Number of Applications: ','numapps');echo '<br>';
            echo form_input($CustCreationNumApps);echo '<br>';
    echo form_label('Version Control: ','versCntrl');echo '<br>';
            echo form_dropdown('versCntrl',$CustCreationVerCntrl,'Subversion'); echo '<br>';
    echo form_label('How often do you test? ','testFreq');echo '<br>';
            echo form_dropdown('freq',$CustCreationTestFreq,'Daily');echo '<br>';
    echo form_submit($CustCreationSubmit,'Submit');    
?> 

但在我提交后,我收到以下错误: img2

是否因为文件 clientcreationmodel.php 与视图和控制器的 clientcreation.php 命名约定不同而引发此错误?

如果我尝试修改模型中的模型类,因为class Classcreation extends CI_Model{}它会引发错误:Fatal error: Cannot redeclare class Clientcreation. 我应该在这里做什么?

4

1 回答 1

1

加载模型后,您将使用小写 c 拼写实例

所以在你的控制器中,它会是

$this->clientcreationmodel->hashed_client_pass_and_submit();

现在注意它的小写字母。

此外,模型第二个参数的加载器不应该是 '' 并且您根本不需要设置第三个参数。你可以这样做,它应该可以正常工作。第二个参数用于设置与默认值不同的对象名称。所以这应该可以正常工作。

$this->load->model('pages/clientcreationmodel');
于 2012-11-06T02:47:07.043 回答