What is the best way to pass objects? What should I do?
Source: Internet
Author: User
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; what is the best way to pass an object?
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;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.