我寫了一些註冊頁面。我想創建成功頁面,並註冊成功信息。 這是我的控制器CodeIgniter - 如何將數組從控制器傳輸到控制器
function register(){
$data['success']=0;
$data['error']=0;
if($_POST){
$config=array(
array(
'field'=>'username',
'label'=>'Login',
'rules'=>'trim|required|min_length[3]|max_length[64]|is_unique[users.username]'
),
array(
'field'=>'email',
'label'=>'Adres email',
'rules'=>'trim|required|is_unique[users.email]|valid_email'
),
array(
'field'=>'password',
'label'=>'Hasło',
'rules'=>'trim|required|min_length[3]|max_length[16]'
),
array(
'field'=>'password2',
'label'=>'Potwierdź hasło',
'rules'=>'trim|required|matches[password]'
),
array(
'field'=>'namePTS',
'label'=>'Imie i nazwisko',
'rules'=>'trim|required|max_length[64]'
),
array(
'field'=>'idPTS',
'label'=>'ID postaci',
'rules'=>'trim|required|integer|max_length[10]'
)
);
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE){
$data['error']=1;
$data['errors']=validation_errors();
} else {
$data=array(
'username'=>$_POST['username'],
'email'=>$_POST['email'],
'password'=>sha1($_POST['password']),
'namePTS'=>$_POST['namePTS'],
'idPTS'=>$_POST['idPTS']
);
$this->load->model('user');
$userid=$this->user->create_user($data);
if(!$userid){
$data['success']=1;
redirect(base_url().'users/success');
}
}
}
$this->load->view('startHeader');
$this->load->view('register',$data);
$this->load->view('startFooter');
}
function success(){
$this->load->view('startHeader');
$this->load->view('success',$data);
$this->load->view('startFooter');
}
這是我的看法
<div class="login-form">
<?php if($success==1){?>
<!-- BEGIN ERROR BOX -->
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<p><b>Success!</b></p>
Registration compleate!.
</div>
<!-- END ERROR BOX -->
<? } ?>
</div>
的樣品,你可以看到,當$這個 - >用戶> create_user($的數據);沒有返回錯誤
$data['success']=1;
redirect(base_url().'users/success');
並在視圖中,如果成功== 1顯示成功框,我有statment。 但我不正確。我有這樣的用戶/成功頁面錯誤
Severity: Notice
Message: Undefined variable: data
Filename: controllers/users.php
Line Number: 99
和
Severity: Notice
Message: Undefined variable: success
Filename: views/success.php
Line Number: 16
我怎麼能這樣做正確嗎?
您必須設置默認的錯誤值,因爲它只是定義,當你有錯誤 – insanebits