I am new to CI and PHP too.
I have a form that which add a company and its contacts to the server including file upload .
i need all things on one button click.
so
function create_company()
{
$insert = $this->database->insert();
return $insert["insertID"]; //returns the inserted ID
}
function file_upload()
{
//upload files if there are some file input selected
return $array_of_uploaded_files;
}
function insert_contacts($company_id,$contacts_array)
{
//return true if everything success
}
My problems are
- First Company insertion is success,but failed to add its contacts,then i need to delete the current inserted item
- If insert_contact failed i need to delete the uploaded files
So is there any way to roll back actions if one or more of its dependency failed ?
I know transactions in Codeignitor ,but how can i use it [with multiple function scope] ?
What about file upload ?
Please note that i am asking this question because i am new to php , what i can do is that create so many functions and call it on appropriate situations.
I just want to know that how can i improve or simplify my codes...
Thank you.