In my model, a Song is linked to a Type. A Type can be Youtube, Soundcloud, Deezer, etc..
When the link value has been validated by my validator, I want to set the style_id value with the correct Type.
What is the best way to do it ?
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.
I think the best way is to perform the check twice:
setLink()so it takes the link, extract the id and save both thelinkand thestyle_idHow to do that.
Create a custom lib, like
lib/videoProvider.class.php. This is kind of prototyped class to valid & retrieve id from a video provider. It, of course, needs improvements.Then in the
doCleanof your validator, you just need to call this class, like that:Finally, the
setLinkin Song.class.php should now be:This is a first draft that must be tested and improved (test if getId() returns an id and not false, same for getProvider, etc …)