我目前正在开发这个php应用程序,其中有一个论坛,我需要编辑某个主题的功能。
我的型号:
public function update_topic(){
$data = array(
'topic_subject' => $this->input->post('topic_subject'),
'body' => $this->input->post('body'),
'topic_cat' => $this->input->post('topic_cat'),
'topic_by' => $this->session->userdata('user_id')
);
$this->db->where('topic_id', $this->input->post('topic_id'));
return $this->db->update('topics', $data);
}
我的控制器:
public function edit($topic_id){
$data['topic'] = $this->topic_model->get_topics($topic_id);
$data['forumcategories'] = $this->forumcategory_model->get_forumcategories();
if(empty($data['topic'])){
show_404();
}
$data['title'] = 'Edit Topic';
$this->load->view('templates/header');
$this->load->view('forum/topics/edit', $data);
$this->load->view('templates/footer');
}
public function update(){
if(!$this->session->userdata('logged_in')){
redirect('users/login');
}
$this->topic_model->update_topic();
// $this->session->set_flashdata('post_updated', 'Post has been updated');
redirect('forumcategories');
}
我的表格:
<h2><?= $title; ?></h2>
<?php echo validation_errors(); ?>
<?php echo form_open('topics/update'); ?>
<div class="form-group">
<label>Topic Subject</label>
<input type="text" class="form-control" name="topic_subject" placeholder="Add Subject" value="<?php echo $topic['topic_subject']; ?>">
</div>
<div class="form-group">
<label>Body</label>
<textarea id="editor" class="form-control" name="body" placeholder="Add text"><?php echo $topic['body']; ?></textarea>
</div>
<div class="form-group">
<label>Category</label>
<select name="category_id" class="form-control">
<?php foreach($forumcategories as $forumcategory): ?>
<option value="<?php echo $forumcategory['cat_id']; ?>"> Name: <?php echo $forumcategory['cat_name']; ?> Description: <?php echo $forumcategory['cat_description']; ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
W
当我点击编辑按钮时,整个信息加载完美,当我提交时,它不会引发任何错误,并将我重定向到我想要的页面,但信息没有更新,这可能是什么问题?
为了更好地练习,这段代码将进入控制器,你能像@Alex所说的那样向我们展示窗体+调试吗
$dataa = array(
'topic_subject' => $this->input->post('topic_subject'),
'body' => $this->input->post('body'),
'topic_cat' => $this->input->post('topic_cat'),
'topic_by' => $this->session->userdata('user_id')
);
然后用$data调用模型
$this->topic_model->update_topic($dataa);