1

我想POST在 CodeIgniter 中编辑一些数据。

问题是当我进行编辑时,我想显示一条消息,告诉我编辑已完成。我尝试执行以下操作,但未显示任何消息。为什么?

控制器

function edit($id = 0) {

    $this->load->model('Event_Model');

    if ($id > 0) {
        $this->data['eventinfo'] = $this->Event_Model->getInfo($id);
    }
    $this->data['pagetitle'] = "Edit";
    $this->data['formID'] = $this->uri->segment(2)."-".$this->uri->segment(3);

    $this->template->build('admin/events/add',$this->data); 
}

function do_edit() {
    $this->load->model('Event_Model');
    $id = $this->input->post('hID');
    $data = array(
       'ev_text' => $this->input->post('ev_text'),
       'ev_pic' => $this->input->post('ev_pic'),
    );
    $this->Event_Model->update($id, $data);

    $this->data['success'] = "Done";
    $this->data['errors'] = $this->errors;
    $this->template->build('admin/events/add',$this->data);     
}

模型

function update($id, $data) {
    $this->db->where('ev_id', $id);
    $this->db->update('events', $data); 
}

查看(我想要消息的地方)

<?php
    if (isset($success)) { ?>
        <div class="alert alert-success normal-alert" style="display: block;">
            <p><span class="ico-text ico-alert-success" ></span><?= $success; ?></p>
        </div>
<?php
    }

    if (isset($errors)) { ?>
        <div class="alert alert-error normal-alert" style="display: block;">
            <div>
                <span class="ico-text ico-alert-error"></span>

                <?php if (count($errors) > 0) { ?>
                    <ul>
                    <?php
                        foreach ($errors as $error) {
                            echo "<li>$error</li>";
                        }
                    ?>
                    </ul>

                <?php } ?>

                <div class="clear"></div>
            </div>
        </div>
    <?php  }  ?>

第二个错误,用图片更新数据不起作用,它让我在配音中出错,称我为$_FILES['choose-file']['name']未定义

4

1 回答 1

0

尝试这个:

控制器

function do_edit() {
    $this->load->model('Event_Model');
    $id = $this->input->post('hID');
    $data = array(
       'ev_text' => $this->input->post('ev_text'),
       'ev_pic' => $this->input->post('ev_pic'),
    );
    $result = $this->Event_Model->update($id, $data);

    if($result) {
        $this->data['success'] = "Done";
        $this->template->build('admin/events/add',$this->data);    
    }


    $this->data['errors'] = $this->errors;
    $this->template->build('admin/events/add',$this->data);     
}

模型:

function update($id, $data) {
    $this->db->where('ev_id', $id);
    $this->db->update('events', $data); 
   return $this->db->affected_rows();
}
于 2013-08-24T12:30:36.120 回答