View Full Version : Using Data transfer objects between script & HTML page

04-23-2008, 05:44 PM
Hello Everybody!

Can I use data transfer objects like JAVA BEANS of java in PHP. I'll illustrate my problem with my example.

Here are Few Files that I use in my application:

1. DataHandler.php // a simple class that connects to database , closes connection, executes, insert/select/update/ delete queries.

2. UserInfo.php // a simple class that have some Getters/ setters methods for accessing a user's attributes.

3. ShowUserInfo.php // A simple file that authenticate & obtain data of a particular user.

4.MyHome.php // A simple view / HTML to show data.

Now whenever a user logged in Showuser.php fetchs data and obtain an object of UserInfo Class, which have some attributes like username, phptoUrl, type(paid/free), Age etc.

Now How ShowUserInfo.php must pass this object to MyHome.php so that it can used as a proper object there.
In order to solve this I passed the object as a session variable as I have to use this object on some other pages too. But on reteriving Values e.g. obj->getUsername(); Php shows an error stating non_object method call or some thing like that.

Please Help. Please tell me also that am I following a good practice or not. as I am new to PHP so I can't get into MVC framework yet. I well be very Obeliged if u could suggest a proper practice to use OOP.
With Warm Regards