Page 1 of 1
how to forward this object to another page ?
Posted: Sat Jan 02, 2010 9:23 pm
by czy11421
how to forward an object to another page ? I tried to put object to Request, but doesn't work.
In controller page, I have
Code: Select all
$myObj = new MyObj();
$_REQUEST["myObj"] = $myObj ;
header("location:../page/p1.php");
in p1.php, I have
Code: Select all
<form action="">
<input value="<?php echo $_REQUEST["myObj"]->getCreateDate(); ?>" type="text" />
</form>
This coding doesn't work. If we don't use Session, how to forward this object to another page ?
Thanks.
Re: how to forward this object to another page ?
Posted: Sat Jan 02, 2010 10:38 pm
by requinix
Either you use sessions or you recreate the object on the second page (by passing whatever information is necessary in the URL).
Re: how to forward this object to another page ?
Posted: Sat Jan 02, 2010 10:57 pm
by manohoo
I'd follow tsairis advice, just create a new object in p1.php.
Just for the sake of learning, if you serialize an object
Code: Select all
$myObjSerialized = serialize($myObj);
header("location:../page/p1.php?object=$myObjSerialized");
Then you can unserialize it in p1.php:
Code: Select all
$myObjUnserialized= unserialize($_REQUEST['object']);
// Now, let's take a look at the object
echo "<pre">;
var_dump($myObjUnserialized);
... but the results are not always predictable. Give it a try, compare the before and after objects and decide if it works for you.
Re: how to forward this object to another page ?
Posted: Sun Jan 03, 2010 11:42 am
by Darhazer
You should include the class definition of the object before trying to unserialize it. And storing the variable in session is the usual way.
Re: how to forward this object to another page ?
Posted: Sun Jan 03, 2010 1:27 pm
by AbraCadaver
Darhazer wrote:You should include the class definition of the object before trying to unserialize it. And storing the variable in session is the usual way.
+1