提交表单后显示 success/error 消息 - codeigniter

displaying success/error messages after form submission - codeigniter

我不知道如何显示成功/错误消息。主要问题是把代码放在哪里。在这里,我插入我的代码。请帮助我完成它。我是 codeigniter 的新手,这里的一切都井井有条。 在此之前,在核心 php 中,我们通过 header('location...'); 传递 error/success 消息;但是,在这里,完全不同。

查看 (index.php)

<?php echo form_open_multipart('welcome/MemberFileUpload');?>
  <input type="file" name="files[]" multiple> <br>
  <input type='submit' value='Submit'>
</form>

控制器

class Welcome extends CI_Controller
{

    public function __construct()
        {
        parent::__construct();
        $this->load->model('news_model');
        $this->load->library('session'); // Start Session
        $this->load->helper('form');
        $this->load->library('form_validation');
        }
 public function member_CAttachments()
 {
     $data['results'] = $this->news_model->member_MAttachments(); 
     $this->load->view('member/templates/header');
     $this->load->view('member/index',$data);
     $this->load->view('member/templates/footer');
    }
  function MemberFileUpload()
    {       
        $this->form_validation->set_rules('FileTitle', 'Title', 'required');
        if ($this->form_validation->run() === FALSE)
            {
            redirect('welcome/member_CAttachments/');
        }
        else
        {
                $FileTitle = $this->input->post('FileTitle');
                $FileDesc = $this->input->post('FileDesc');
            $CurrentDate=date("Y-m-d h:i:s");
            $InsertedFileID=$this->news_model->UploadFileDetails($FileDesc, $CurrentDate,$FileTitle);

            $UploadDirectory='assets/Upload/';
            $TotalUploadedFiles=count($_FILES['files']['name']);

            for($i=0;$i<$TotalUploadedFiles;$i++)
            {
                $UploadedFileName=$_FILES['files']['name'][$i];
                $EncFileName=time().$UploadedFileName;
                if(move_uploaded_file($_FILES['files']['tmp_name'][$i], $UploadDirectory.$EncFileName))
                    {
                    $this->news_model->UploadFiles($InsertedFileID, $EncFileName);
                } 
            }
            redirect('welcome/member_CAttachments/');
        }
     }
}

型号

class News_model extends CI_Model 
{

        public function __construct()
        {
                $this->load->database();
        }
        public function UploadFiles($InsertedFileID,$EncFileName)
        {
            $MemberData = array(
            'FileID' => $InsertedFileID,
            'FilePath' => $EncFileName
            );

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

您的上传代码重定向到

 redirect('welcome/member_CAttachments/');

在该模板中,您应该放置 error/success 代码

将此添加到您的控制器:

$this->session->set_flashdata('response',"Data Inserted Successfully");
redirect('welcome/member_CAttachments/');

将此添加到您的视图中:

echo $this->session->flashdata('response');