表单提交后显示成功/错误消息 - codeigniter

时间:2015-08-26 14:39:56

标签: php codeigniter

我无法知道如何显示成功/错误消息。主要问题是放置代码的位置。在这里,我正在插入我的代码。请帮我详细说明一下。我是codeigniter的新手,这里的一切都井然有序。 在此之前,在核心php中,我们通过标题传递错误/成功消息('location ...');但是,这里完全不同。

查看(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);
       }
}

1 个答案:

答案 0 :(得分:0)

您的上传代码重定向到

 redirect('welcome/member_CAttachments/');

在该模板中,您应该放置错误/成功代码