Does anyone know how to add multiple records using just one form in Yii? All the records belong to the same model and are of the same format.
Many thanks,
Nick
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.
The equivalent “batchCreate” method of the “batchUpdate” from the guide could be something like this:
The only concern here is that a new instance has to be created for each model that you are saving, using
new. The rest of the logic can be implemented in any way you wish, for example in the above example all the models are being validated, and then saved, whereas you could have stopped validation if any model was invalid, or maybe directly saved the models, letting validation happen duringsavecall. So the logic will really depend on your app’s ux.