Welcome Guest, Not a member yet? Register   Sign In
Routing problem
#1

[eluser]hostingx[/eluser]
Hello all!

Problems again,

When people add comments to my blog, i want them to be send back to the blog item, but here comes the problem, when i use the validation class/helper, i need to use: $this->load->view('viewname');

But that means i cant give an ID with the uri, so the application knows what blog entry he need to load,

here the code i have untill now:

Code:
function add_comment()
    {
        $this->template['link'] = 'home';
        $this->template['title'] = 'Add comment';
        
        $this->load->library('validation');
        
        $rules['name']         = "required";
        $rules['email']     = "required|email";
        $rules['message']     = "required";
        
        $fields['name']        = 'Name';
        $fields['email']     = 'Email';
        $fields['message']    = 'Message';
            
        $this->validation->set_error_delimiters('<fieldset id="error">', '</fieldset>');
        $this->validation->set_rules($rules);
        $this->validation->set_fields($fields);
        
        if ($this->validation->run() == FALSE)
        {
            $this->_run('item'.$this->uri->segment(3));    
        }
        else
        {
            $blog_entry = array(
                'name' => $this->input->post('name'),
                'email' => $this->input->post('email'),
                'entryid' => $this->uri->segment(3),
                'message' => $this->input->post('message'),
                'date'    => date('Y/m/d')
            );
            if ($this->blog_model->Add_comment($blog_entry))
            {
                $this->template['report'] = 'Your comment was succesfully added';
                $this->_run('item'.$this->uri->segment(3));        
            }
            else
            {
                die ('Error, something went wrong, please try again!!!!');
            }
        }          
    }

I hope you people can help me out :o
#2

[eluser]tonanbarbarian[/eluser]
Code:
$this->db->insert_id();
Will return the id of the last record inserted.

If your Add_comment method only ever adds, not updates, the comments then you can simply use the above code to determine the id
My suggestion would be to put some clode in the model to store the id as a property of the model
i.e.
Code:
function Add_comment($blog_entry) {
...
...
...
  $this->id = $this->db->insert_id();
  return $return;
} // Add_comment()

Then in your controller you can find the id by
Code:
$this->blog_model->id;

If Add_comment can be used to update as well as insert then you need a bit more logic to determine if this is a new or exiting record, but this should be a good start for you
#3

[eluser]Phil Sturgeon[/eluser]
What are you talking about? Show them the view if they need to see the form, if they are done use redirect and grab the $this->uri->segment(3) as you are already doing.




Theme © iAndrew 2016 - Forum software by © MyBB