Page 1 of 1
how to store object in request scope
Posted: Wed Jul 18, 2007 8:07 am
by alaa56mm
dear all..
iam J2EE developer,and new tophp,in jsp , there are a functionality to store object (e.g, UserVO) on request scope,like
i mean when i am at a page1.php, and want to go to page2.php,i should store Object on request Scope when iam in page1.php, then getting this object when iam at page2.php...
how can i do this in php????
Regards
Posted: Wed Jul 18, 2007 8:11 am
by Begby
it's 'I am' not 'iam' and believe it or not you are supposed to have a space after commas.
There is not request object scope built into PHP. You have to append the variables to links like '
http://mysite.com/index.php?myvar=value' to get them to pass to the next page.
You can also make use of sessions to store variables between page requests. Check out the php.net manual.
ok
Posted: Wed Jul 18, 2007 8:17 am
by alaa56mm
having a space after commas or not. will not resolve the question?
thanks man for your replying..but i dont want to put it in query string like you said...
i believe that there is a solution for this problem
Posted: Wed Jul 18, 2007 8:19 am
by Zoxive
Posted: Wed Jul 18, 2007 8:24 am
by alaa56mm
can you kindly give me am example scenario, so i want to see how you store the object and how get it in each page??
regards
Posted: Wed Jul 18, 2007 8:29 am
by Zoxive
You can't necessarily store objects, you store strings/variables/arrays.
Page1.php
Code: Select all
session_start();
$_SESSION['Hi'] = 'Hi from page 1';
Page2.php
Code: Select all
session_start();
echo $_SESSION['Hi']; // Hi from page 1;
Posted: Wed Jul 18, 2007 9:41 am
by volka
Objects can be stored in $_SESSION as long as the class definition is present when the session data is unserialized, i.e. before calling session_start().
But the java request object has nothing to do with sessions. It represents data of the current request. If the request is handled the request object is gone, just like $_POST, $_GET and the whole php instance.
If you inlucde/require another php script it is imported into the same php instance and shares the variables of the including script.
You might want to try something like
Code: Select all
$xyz = 'some data';
require 'another_script.php';
if you want to make sure the variables are in the global scope you can try
Code: Select all
$GLOBALS['xyz'] = 'some data';
require 'another_script.php';
Code: Select all
// another_script.php
echo $GLOBALS['xyz'];