Is there a way after the ->save() call to get the last insert id?
Example Code:
$post_data = $_POST;
$user = ORM::factory('user');
$user->username = $post_data['username'];
$user->email = $post_data['email'];
$user->save();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Of course, assuming your insert code looked like this:
To get the last insert ID simply do this after the call to
->save()In your case you would need to do
$user->user_idas you’ve named your primary keyuser_id.I would alternatively recommend biakaveron’s advice to instead use
$user->pk()as it will always return the value of the primary key regardless of the name given to it, provided that you specify the primary key name in your model with$_primary_key.The model will be populated with the saved values ready for reuse if the insert worked.
Job done!