所以,我要做的就是从表单输入向数据库提交一些值。
我有一个控制器 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');
?>
但在我提交后,我收到以下错误:
是否抛出此错误,因为clientcreationmodel.php文件与clientcreation.php的命名约定与视图和控制器的命名约定相同?
如果我尝试将模型中的模型类修改为class Classcreation extends CI_Model{}
,则会抛出错误:Fatal error: Cannot redeclare class Clientcreation
。我该怎么办?
答案 0 :(得分:1)
加载模型后,您将使用小写c拼写实例
所以在你的控制器中,它将是
$this->clientcreationmodel->hashed_client_pass_and_submit();
现在注意它的小写。
另外,模型第二个参数的加载器不应该是'',你根本不需要设置第三个参数。你可以这样做,它应该工作正常。第二个参数用于设置与默认值不同的对象名称。所以这应该可以正常工作。
$this->load->model('pages/clientcreationmodel');