Jump to content

AJAX and Objects


ShadowMage

Recommended Posts

Hey guys, I'd like some opinions on something.I'm working on a large project which uses a somewhat large PHP class. This class has approximately 20 to 30 attributes (private and public) and probably 10 to 15 different methods (private and public). Some of these methods are incredibly complex, doing very long and complicated calculations, generating large arrays, and printing entire HTML pages.This object is first created using information stored in a database when a user enters a certain page. This page is completely generated by the object. The purpose of this page is to be able to edit the information used to generate the object.I have a need to be able to perform many of the calculations on the fly whenever page elements are updated. I can think of two ways to accomplish this task:- Duplicate the methods in JavaScript. I don't really like this method since it will require an incredible amount of maintenance if anything ever needs to be changed. Plus there's the challenge of debugging calculation errors to make sure that the PHP and JavaScript calculate everything exactly the same.- Use AJAX to send information to a PHP script which uses the calculations I've already written in PHPI think AJAX is probably the way to go (but correct me if I'm wrong) so that's the route I've decided to take. But now I have another situation. I need to be able to access the attributes and methods of my class. Again, I can think of two ways to do this:- Recreate the object using $_POST data sent by the AJAX request. The problem here is that the parameter string will be huge and require many lines of JavaScript to construct.- Serialize and store an existing object in the session and then unserialize it again when I need it. This will save me from having to recreate the object, but I've read that large objects should not be stored in the session.Which of these is the best way to go? What are the performance (dis)advantages? Are there other ways to do this that I'm not thinking of?Please help and thanks in advance. (I hope all of this made sense....)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...