[eluser]A83[/eluser]
Thanks for the fast answer!
It looks promising, I've tried to implement it but, when I load the Model the document goes blank.
This is my controller now:
Code:
<?php
class Greeting extends Controller {
function Greeting()
{
parent::Controller();
//$this->load->model('Greeting_model', '', TRUE);
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
function index()
{
$this->db->where('id', $this->uri->segment(1));
$data['query'] = $this->db->get('greetings');
$this->load->library('form_validation');
$this->form_validation->set_message('required', 'Måste finnas');
$this->form_validation->set_message('min_length', 'Minst 2 bokstäver');
$this->form_validation->set_message('valid_email', 'Måste vara en korrekt e-post');
$this->form_validation->set_rules('from', 'From', 'trim|required|min_length[2]');
$this->form_validation->set_rules('from_mail', 'From e-mail', 'trim|required|valid_email');
$this->form_validation->set_rules('to', 'To', 'trim|required|min_length[2]');
$this->form_validation->set_rules('to_mail', 'To e-mail', 'trim|valid_email');
$this->form_validation->set_rules('msg', 'Message', 'trim');
if ($this->form_validation->run()) {
$post = array('from' => $this->input->post('from'),
'from_mail' => $this->input->post('from_mail'),
'to' => $this->input->post('to'),
'to_mail' => $this->input->post('to_mail'),
'msg' => $this->input->post('msg'),
'from_greeting' => $this->input->post('from_greeting'),
'ip' => $this->input->ip_address()
);
if ($this->post->save($post)) {
// Our model will populate the class variable if a post was saved
// We can redirect to a method that will display that post
redirect('send/' . $this->post->last_id);
}
}
// The form wasn't processed - display it
$this->load->view('greeting_view', $data);
}
}
And the model:
Code:
<?php
class Greeting_model extends Model {
var $last_id
function Greeting_model()
{
parent::Model();
}
function save($post = array()) {
if (count($post) > 0) {
$this->db->insert('greetings', $post);
if ($this->db->affected_rows() == 1) {
$this->last_id = $this->db->insert_id();
return TRUE;
}
}
return FALSE;
}
}