So my controller looks like this:
public function insert(){
//form_validation_rules
if($this->form_validation->run() == FALSE){
//redirect to view
}else{
//get data here $this->input->post()
//insert into table here all others depend on this table to exist
//returns story_id
if($table_id){
// here i have to insert data into 4 more table.
}
}
}
So i have to insert into story table first since the story has to exist before i insert the genre/tags/content warning and finally the chapter since in my form to create a new story you have to add the first chapter too.
An answer to my previous question told me a nested if is bad practice and ive also searched here and saw this: PHP - Nested IF statements
My confusion is, where do i process and insert my data if i were to follow a scheme like that?
Writing this question up to here, my brain cleared up a bit, so i might aswell ask if i am right or in the right direction.
So i'll do it like this:
//process data here
$insert_genre = $this->model->insert_genre($genre);
$insert_tag = $this->model->insert_tags($tags);
$insert_warning = $this->model->insert_warning($content_warning);
$insert_chapter = $this->model->add_chapter($chapter);
if(!insert genre){
//redirect view }
if(!insert tags){
//redirect view }
if(!insert content_warning){
//redirect view }
if(!insert chapter){
//redirect view }
else{
//load view
}
EDIT:
This is how my model method for inserting genre/tag/contentwarning looks: theyre all similarly written.
public function new_story_genre($genre){
$inserted = 0;
foreach($genre as $row){
$this->db->insert('story_genre', $row);
$inserted += $this->db->affected_rows();}
if($inserted == count($genre)){
return TRUE;}else{ return FALSE; }
}