开发者

cakephp lookup value if not in database

开发者 https://www.devze.com 2023-01-07 07:48 出处:网络
I\'m stll relatively new to cakephp (1.3) and struggling with where to put the code to do the following.

I'm stll relatively new to cakephp (1.3) and struggling with where to put the code to do the following.

I 开发者_JS百科want to display fields from a database (as usual) but, if the value for one of the fields is null, I want to look up the value using a web service and, if the request is successful, write the returned value to the database before returning the new value. I've already written the code to look up the web service, I'm just not sure exactly where to put it (model or controller) to make it work most effectively.

Thanks - I'd appreciate any suggestions.


I would suggest putting this in your Model within a afterFind() function. This function is automatically triggered after any find() operations are performed within that model. Within this function, you could check the value of the field, perform your lookup if necessary and update the field.

Read about how to implement this here: http://book.cakephp.org/view/1048/Callback-Methods


Would you put your web service call in the controller, and pass the returned data to the model to be put into the database. Tom.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号