我不确定将成功消息实现到不同 div 的最佳方法是什么。
当页面加载时,我也将错误 div 加载到我的视图中,为什么?我希望它仅在出现错误时才显示。
如果没有错误,我如何更改 div 并包含成功消息?
看法:
<div class="alert alert-error">
<?php echo validation_errors();?>
</div>
控制器:
if($this->form_validation->run() === TRUE)
{
$userData = array(
'fName' => $this->input->post('userFirstName', TRUE),
'lName' => $this->input->post('userLastName', TRUE),
'email' => $this->input->post('userEmail', TRUE),
'password' => sha1($this->input->post('userPassword', TRUE))
);
$this->db->escape($userData);
$this->user_model->addUser($userData);
}
$data['contentMangement'] = $this->options_model->systemOptions();
$data['pageTitle'] = 'Add User';
$this->load->view('_assets/header', $data);
$this->load->view('addUser', $data);
$this->load->view('_assets/footer');
}
更新:
<?php
$errorMessage = validation_errors('<div class="alert alert-error">', '</div>');
$successMessage = '<div class="alert alert-success"><strong>Thank You</strong> Your User Has Been Added';
if($errorMessage)
{
echo $errorMessage;
}else{
echo $successMessage;
}
?>