Welcome Guest, Not a member yet? Register   Sign In
[Beginner] Controller issue
#11

[eluser]Ashley Snowdon[/eluser]
Hi n0xie, thank you very much for taking the time to post. This helps a lot and I will modify my existing controller and model to this.

In my cron2 function, I read in several remote XML files, grab some elements and store them in the database in a separate table. Would it be ideal to place this in a separate model, or stick to the same one? The XMLs range between info for the above-mentioned servers, and something unrelated.

Many thanks.
#12

[eluser]n0xie[/eluser]
It kinda depends. The fetching and handling of the XML probably works the same for all XML's so I would isolate that into 1 function/method/model/library. If the XML share similarities it would make sense to group them together. If not you might have to handle each differently or if they have some base similarity use polymorphism to handle the differences. It also depends what problem you are trying to solve. It might be you're trying to do too much in one 'go' and you would be better off breaking it up into separate cron jobs. I would need to see some example code to give you a better perspective.

The key lesson here is to try and break up your code into small bits, group those bits together that share similarities, move those bits into a single class thus hiding away the implementation, then call those bits from your controller. This way your controller 'controls' what should be done and your model/library controls how.

If you get familiar with OOP you will see that it is kind of like having a conversation with your code:
Your controller says 'grab that XML', then your model/library does the actual work. Then your controller says if the XML is gives an error, take care of that, else, process the XML. etc etc.




Theme © iAndrew 2016 - Forum software by © MyBB