What is the best way to pass objects? I used to learn JAVA because I wanted to use PHP for something. MVC: mode. Code: UserInfoAction. class. php & nbsp;: public & nbsp; function & nbsp; index ($ userid) {& nbsp; $ userdao & nbsp; what is the best way to pass objects?
I used to learn JAVA because I wanted to use PHP for something. MVC: mode. Code:
UserInfoAction. class. php:
Public function index ($ userid ){
$ Userdao = new UserDao ();
$ UserVo = $ userdao-> findUserById ($ userid );
Jump to: UserInfo. php
}
For JAVA, it is easy: pagecontext. setAttribute ('uservo ', userVo );
Pagecontext. forward (UserInfo. jsp );
On the UserInfo. jsp page, you only need to: userVo uservo = request. getAttribute ('uservo '); then you can get the object.
**************************************** **************************************** *******
Let's take a look: object transfer between PHP pages. There are several possible types.
1. object serialization $ userVoStr = serialize ($ userVo); $ _ SESSION ['uservo'] = $ userVoStr; (Session pear is too large)
2. pass $ URL = UserInfo. php Through url? UserVo = urlencode ($ userVoStr); header ("Location: $ url"); (it may be too long)
3. you can also use Form to hide VO objects passed by fields. (This estimation speed is not good, and this is an extra step ).
Massive data: for example, how should ListUsers pass the data to another page. If Session is used, whether or not the Session needs to be passed and then manually cleared. In JSP, sessions are generally not used for page transfer of a large amount of data.
------ Solution --------------------
Discussion
......
2. pass $ URL = UserInfo. php Through url? UserVo = urlencode ($ userVoStr); header ("Location: $ url"); (it may be too long)
......
------ Solution --------------------
The issues you are concerned about are common. php does not survive in a vacuum. So he also needs to respond to all possible situations at the time.
Otherwise, he will not be able to survive. Although the response may be unsatisfactory
In your description, the preferred solution provided by php is session.
Pagecontext. setAttribute ('uservo ', userVo );
Yes
Session_start ();
$ _ SESSION ['uservo '] = $ userVo;
Corresponding
UserVo uservo = request. getAttribute ('uservo ');
Yes
Include 'userdao-like definition filename ';
Session_start ();
$ UserVo = $ _ SESSION ['uservo '];
While serialize and unserialize are only used as alternatives