Welcome Guest, Not a member yet? Register   Sign In
Codeigniter4 How can i use different field for save() method as primary key
#2

(This post was last modified: 03-21-2024, 11:32 PM by luckmoshy.)

(03-21-2024, 03:22 AM)sarath_unrelax Wrote: Dear Friends,

I have a application where HR department can upload a xlsx file to add/update employees records. In the employees table i have id as primary key which i used for other operations like edit, delete etc...
For this xlsx file upload functionality i need to use save() method after parsing the data from the file for that i cannot let HR to specify a primary key, instead of that there is one field called "emp_code", how i can use that field as primary key only for the save() method after processing the uploaded xlsx file ?

Here is my controller where i process the xlsx file :


Code:
$data_to_save = [

                                'first_name' => $first_name,
                                'last_name' => $last_name,
                                'date_of_joining' => $date_of_joining,
                                'emp_code' => $emp_code,
                                'email' => $email,
                                'dob' => $dob,
                                'reporting_to' => $reporting_to,
                                

                            ];

                            if($this->model->save($data_to_save)) {

                                $response = ["status" => "success", "message" => "", "type" => "insertion"];
                            }
                            else {

                                $response = ["status" => "error", "message" => "error in data" , "type" => "insertion"];

                            }

In model i changed primaryKey = "emp_code" but that works for my save but that stops the other functions like edit and delete.

can you please read here carefully please https://codeigniter.com/user_guide/tutor...ews-method
you will see that instead of the primary key yet, we can update or delete the data as you wish
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply


Messages In This Thread
RE: Codeigniter4 How can i use different field for save() method as primary key - by luckmoshy - 03-21-2024, 11:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB