Hello,
I have a web page with Employee Id/Name etc and then the employees salary components as lineitems on the same web page. The Employee & Employee Component models are related by one->many relationship. User can modify the employee or component details (lineitems) on this web page as all fields are input boxes. How do I retrieve all the lineitem rows using php and invoke save of employee and all related records. The php code below gets just one lineitem row. I believe I will have to use jquery/javascript & ajax. Even if I use that, how do I pass the lineitem info to the PayEmpComponents class before save()
is called. I believe I have to get all the employee components as lineitems and set them to empComp[0], empComp[1].... I have searched a lot on the internet but still am unclear how to do it. If somebody can give a code snippet that will be a big help.
Some of my edit Action code in the controller looks like below:
$employee->setHrEmpIid($this->request->getPost("hr_emp_iid", 'striptags'));
$employee->setHrEmpId($this->request->getPost("hr_emp_id", 'striptags'));
$employee->setHrEmpFname($this->request->getPost("hr_emp_fname", 'striptags'));
$employee->setHrEmpLname($this->request->getPost("hr_emp_lname", 'striptags'));
$employee->setHrEmpGender($this->request->getPost("hr_emp_gender", 'striptags'));
$employee->setHrEmpDob($this->request->getPost("hr_emp_dob", 'striptags'));
$employee->setHrEmpMob($this->request->getPost("hr_emp_mob", 'striptags'));
$employee->setHrEmpDoj($this->request->getPost("hr_emp_doj", 'striptags'));
//foreach (empComp)
{
$empComp = new PayEmpComponents() ;
$empComp->setHrEmpIid($this->request->getPost("empComp_hr_emp_iid", 'striptags')) ;
$empComp->setPayEmpCompoIid($this->request->getPost("empComp_pay_emp_compo_iid", 'striptags')) ;
$empComp->setPayCompoIid($this->request->getPost("empComp_pay_compo_iid", 'striptags')) ;
$empComp->setPayCompoPercent($this->request->getPost("empComp_pay_compo_percent", 'striptags')) ;
}
$employee->PayEmpComponents = $empComp ;
if (!$employee->save()) {
$this->flash->error($employee->getMessages());
} else {
.....
Thanks in advance