[eluser]Egill Th[/eluser]
Here is a small example on how you could update news posts, I haven't tested it out but you should be able to work with this and alter it to suit your needs.
News.php controller
Code:
<?php
class News extends CI_Controller {
var $data;
public function __construct() {
$this->load->model('newsmodel');
}
public function updateNewsItem($id) {
$this->data['item'] = $this->newsmodel->getNewsItem($this->db->escape($id));
if(isset($_POST['submit'])) {
$this->newsmodel->updateNewsItem(
$this->db->escape($id),
array(
'subject' => $this->db->escape($this->input->post('subject')),
'body' => $this->db->escape($this->input->post('body')),
)
);
redirect('news/view/' . $id . '/');
}
$this->load->view('updateNews.php', $this->data);
}
}
Newsmodel.php model
Code:
<?php
class Newsmodel extends CI_Model {
var $table = 'newspost';
public function __construct() {
parent::__construct();
}
public function getNewsItem($id) {
$result = $this->db->get_where('newspost', array('id', $id));
return $result->result();
}
public function updateNewsItem($id, $data) {
$this->db->where('id', $id);
$this->db->update('newspost', $data);
}
updateNews.php view
Code:
<form method="post">
<input id="subject" name="subject" type="text" value="<?php echo $item[0]->subject; ?>">
<textarea id="body" name="body"><?php echo $item[0]->body; ?></textarea>
<input name="submit" type="submit" value="Submit changes">
</form>