Example Flex Zend AMF Sharing Web Services Between Components in ViewStack
I've been searching for the last couple days but can't seem to find a basic example of what I'm looking for. I'm developing a Flex 4.5 app and in it I have a viewstack of 2 components that use some of the same services. Currently the only way I can get the app to correctly use the web services is by defining 2 different web services that use the same PHP web service file.
For example: I have an app, and within it I have a viewstack with tab navigation of 2 components: #1) retrieve a list of all Salary Employees, and #2) retrieve a list of all Contractors. Currently to get it working I am defining a UsersTableEmployees webservice within component #1 and a UsersTableContractors webservice within component #2, but they both point to the same PHP class, and only differ in the arugment value I pass to them. Ie, getUsers("employee") and getUsers("contractors"). Of cour开发者_开发问答se this is not best practice.
Searching StackOverflow and Google gives me many results about ColdFusion and MVC (example What's the best way to share data between components in Flex?), but I'm still confused. Can anyone here point me to a basic example (even sample MVC) and source code of an app that uses Zend AMF and allows different components to call common web services?
Thank you!
Just use some basic encapsulation.
Wrap up the service code into a single class; and pass an instance of that class into your view component. Or you could create a single instance of the services class and pass it into each view component as a property.
If you wanted, you can get much more complicated with it, though. Many Frameworks, such as Robotlegs or Swiz, try to help solve this problem.
精彩评论